Skip to content

Commit

Permalink
[CI] Remove unittest TestRunner support
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Jan 14, 2022
1 parent ec85c24 commit 97f69b4
Showing 1 changed file with 21 additions and 70 deletions.
91 changes: 21 additions & 70 deletions test/python/runCythonTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This script gathers all the tests defined 'cantera.test' module, runs them,
and prints a report. Extra command line arguments can be used to run subsets
of the test suite, e.g.:
of the test suite, for example:
all tests from 'test_thermo.py' and 'test_kinetics.py':
Expand All @@ -25,41 +25,10 @@
cantera_root = os.path.relpath(__file__).split(os.sep)[:-1] + ['..', '..']
os.chdir(os.sep.join(cantera_root + ['test', 'work']))

import unittest
try:
import pytest
except ImportError:
pytest = None
import pytest
import cantera
import cantera.test

class TestResult(unittest.TextTestResult):
def __init__(self, *args, **kwargs):
unittest.TextTestResult.__init__(self, *args, **kwargs)
self.outName = 'python-results.txt'
with open(self.outName, 'w') as f:
pass # just create an empty output file

def reformat(self, test_string):
name, cls = test_string.split()
cls = cls.replace('(cantera.test.', '').replace(')','')
return '%s.%s' % (cls, name)

def addSuccess(self, test):
with open(self.outName, 'a') as f:
f.write('PASS: %s\n' % self.reformat(str(test)))
unittest.TextTestResult.addSuccess(self, test)

def addFailure(self, test, err):
with open(self.outName, 'a') as f:
f.write('FAIL: %s\n' % self.reformat(str(test)))
unittest.TextTestResult.addFailure(self, test, err)

def addError(self, test, err):
with open(self.outName, 'a') as f:
f.write('ERROR: %s\n' % self.reformat(str(test)))
unittest.TextTestResult.addFailure(self, test, err)


if __name__ == '__main__':
print('\n* INFO: using Cantera module found at this location:')
Expand All @@ -82,41 +51,23 @@ def addError(self, test, err):
verbose = True
subset_start += 1

if pytest is not None:
base = Path(cantera.__file__).parent.joinpath('test')
subsets = []
for name in sys.argv[subset_start:]:
subsets.append(str(base.joinpath(f"test_{name}.py")))

if not subsets:
subsets.append(str(base))

pytest_args = ["-raP", "--junitxml=pytest.xml"]
if show_long:
pytest_args += ["--durations=50"]
if fast_fail:
pytest_args.insert(0, "-x")
if verbose:
pytest_args.insert(0, "-v")
else:
pytest_args.append("--log-level=ERROR")

ret_code = pytest.main(pytest_args + subsets)
sys.exit(ret_code)
base = Path(cantera.__file__).parent.joinpath('test')
subsets = []
for name in sys.argv[subset_start:]:
subsets.append(str(base.joinpath(f"test_{name}.py")))

if not subsets:
subsets.append(str(base))

pytest_args = ["-raP", "--junitxml=pytest.xml"]
if show_long:
pytest_args += ["--durations=50"]
if fast_fail:
pytest_args.insert(0, "-x")
if verbose:
pytest_args.insert(0, "-v")
else:
loader = unittest.TestLoader()
runner = unittest.TextTestRunner(
verbosity=2, resultclass=TestResult, failfast=fast_fail
)
suite = unittest.TestSuite()
subsets = []
for name in sys.argv[subset_start:]:
subsets.append('cantera.test.test_' + name)

if not subsets:
subsets.append('cantera.test')

suite = loader.loadTestsFromNames(subsets)

results = runner.run(suite)
sys.exit(len(results.errors) + len(results.failures))
pytest_args.append("--log-level=ERROR")

ret_code = pytest.main(pytest_args + subsets)
sys.exit(ret_code)

0 comments on commit 97f69b4

Please sign in to comment.