diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2017-07-08 20:31:37 -0600 |
|---|---|---|
| committer | xoviat <xoviat@users.noreply.github.com> | 2017-12-22 17:30:50 -0600 |
| commit | 787b4a094c0a4f2aac338fe2a22e6e923ea14baa (patch) | |
| tree | a8c5fd49891b3067c2f223a0b26422904cb47ac5 /numpy/testing | |
| parent | 604d21792b6e1125dae54f1905bcd8b4a70e912f (diff) | |
| download | numpy-787b4a094c0a4f2aac338fe2a22e6e923ea14baa.tar.gz | |
ENH: Add pytest compatible run_module_suite.
Diffstat (limited to 'numpy/testing')
| -rw-r--r-- | numpy/testing/pytest_tools/nosetester.py | 86 |
1 files changed, 40 insertions, 46 deletions
diff --git a/numpy/testing/pytest_tools/nosetester.py b/numpy/testing/pytest_tools/nosetester.py index 9aab133da..6283072b3 100644 --- a/numpy/testing/pytest_tools/nosetester.py +++ b/numpy/testing/pytest_tools/nosetester.py @@ -61,60 +61,58 @@ def get_package_name(filepath): return '.'.join(pkg_name) -if False: - # disable run_module_suite and NoseTester - # until later - def run_module_suite(file_to_run=None, argv=None): - """ - Run a test module. +def run_module_suite(file_to_run=None, argv=None): + """ + Run a test module. - Equivalent to calling ``$ nosetests <argv> <file_to_run>`` from - the command line + Equivalent to calling ``$ nosetests <argv> <file_to_run>`` from + the command line. This version is for pytest rather than nose. - Parameters - ---------- - file_to_run : str, optional - Path to test module, or None. - By default, run the module from which this function is called. - argv : list of strings - Arguments to be passed to the nose test runner. ``argv[0]`` is - ignored. All command line arguments accepted by ``nosetests`` - will work. If it is the default value None, sys.argv is used. + Parameters + ---------- + file_to_run : str, optional + Path to test module, or None. + By default, run the module from which this function is called. + argv : list of strings + Arguments to be passed to the pytest runner. ``argv[0]`` is + ignored. All command line arguments accepted by ``pytest`` + will work. If it is the default value None, sys.argv is used. - .. versionadded:: 1.9.0 + .. versionadded:: 1.14.0 - Examples - -------- - Adding the following:: + Examples + -------- + Adding the following:: - if __name__ == "__main__" : - run_module_suite(argv=sys.argv) + if __name__ == "__main__" : + run_module_suite(argv=sys.argv) - at the end of a test module will run the tests when that module is - called in the python interpreter. + at the end of a test module will run the tests when that module is + called in the python interpreter. - Alternatively, calling:: + Alternatively, calling:: - >>> run_module_suite(file_to_run="numpy/tests/test_matlib.py") + >>> run_module_suite(file_to_run="numpy/tests/test_matlib.py") - from an interpreter will run all the test routine in 'test_matlib.py'. - """ + from an interpreter will run all the test routine in 'test_matlib.py'. + """ + import pytest + if file_to_run is None: + f = sys._getframe(1) + file_to_run = f.f_locals.get('__file__', None) if file_to_run is None: - f = sys._getframe(1) - file_to_run = f.f_locals.get('__file__', None) - if file_to_run is None: - raise AssertionError - - if argv is None: - argv = sys.argv + [file_to_run] - else: - argv = argv + [file_to_run] + raise AssertionError - nose = import_nose() - from .noseclasses import KnownFailurePlugin - nose.run(argv=argv, addplugins=[KnownFailurePlugin()]) + if argv is None: + argv = sys.argv + [file_to_run] + else: + argv = argv + [file_to_run] + pytest.main(argv) +if False: + # disable run_module_suite and NoseTester + # until later class NoseTester(object): """ Nose test runner. @@ -546,10 +544,6 @@ if False: return nose.run(argv=argv, addplugins=add_plugins) else: - def run_module_suite(file_to_run=None, argv=None): - pass - - class NoseTester(object): def __init__(self, package=None, raise_warnings="release", depth=0): pass @@ -561,7 +555,7 @@ else: def bench(self, label='fast', verbose=1, extra_argv=None): pass - + def _numpy_tester(): if hasattr(np, "__version__") and ".dev0" in np.__version__: |
