Run just the test functions that match a given pattern?

With runtests.py, we can run the tests for a specific module (e.g. `-s stats`), a specific file (e.g. `-t scipy.stats.tests.test_stats`), or a specific class or function within a file (e.g. `-s scipy.stats.tests.test_stats::TestCorrPearsonr`, `-s scipy.stats.tests.test_stats::test_kendalltau`). Is there a way to run the tests whose names match a given pattern? For example, I'd like to use the pattern `*ttest_rel*` to run any test that has `ttest_rel` in its name. I can hack this by adding the line python_functions = *ttest_rel* to pytest.ini, and then comment out that line when I want to run a larger set of tests, but it would be nice if a pattern could be given in the command line. Warren

On 19/4/20 6:06 pm, Warren Weckesser wrote:
With runtests.py, we can run the tests for a specific module (e.g. `-s stats`), a specific file (e.g. `-t scipy.stats.tests.test_stats`), or a specific class or function within a file (e.g. `-s scipy.stats.tests.test_stats::TestCorrPearsonr`, `-s scipy.stats.tests.test_stats::test_kendalltau`). Is there a way to run the tests whose names match a given pattern? For example, I'd like to use the pattern `*ttest_rel*` to run any test that has `ttest_rel` in its name.
I can hack this by adding the line
python_functions = *ttest_rel*
to pytest.ini, and then comment out that line when I want to run a larger set of tests, but it would be nice if a pattern could be given in the command line.
Warren
I think this is a documentation issue. Since scipy uses pytest under the hood to actually run the tests, any extra arguments after `--` are passed to pytest, so you should be able to use `python runtest.py -- -k "*ttest_rel*' which will use pytest's regex test chooser. At least that is the way it works on numpy ... Matti

On 4/19/20, Matti Picus <matti.picus@gmail.com> wrote:
On 19/4/20 6:06 pm, Warren Weckesser wrote:
With runtests.py, we can run the tests for a specific module (e.g. `-s stats`), a specific file (e.g. `-t scipy.stats.tests.test_stats`), or a specific class or function within a file (e.g. `-s scipy.stats.tests.test_stats::TestCorrPearsonr`, `-s scipy.stats.tests.test_stats::test_kendalltau`). Is there a way to run the tests whose names match a given pattern? For example, I'd like to use the pattern `*ttest_rel*` to run any test that has `ttest_rel` in its name.
I can hack this by adding the line
python_functions = *ttest_rel*
to pytest.ini, and then comment out that line when I want to run a larger set of tests, but it would be nice if a pattern could be given in the command line.
Warren
I think this is a documentation issue. Since scipy uses pytest under the hood to actually run the tests, any extra arguments after `--` are passed to pytest, so you should be able to use `python runtest.py -- -k "*ttest_rel*' which will use pytest's regex test chooser. At least that is the way it works on numpy ...
Thanks Matti! I sent my previous email before I saw yours. -k works for me. Warren
Matti
_______________________________________________ SciPy-Dev mailing list SciPy-Dev@python.org https://mail.python.org/mailman/listinfo/scipy-dev

On 4/19/20, Warren Weckesser <warren.weckesser@gmail.com> wrote:
With runtests.py, we can run the tests for a specific module (e.g. `-s stats`), a specific file (e.g. `-t scipy.stats.tests.test_stats`), or a specific class or function within a file (e.g. `-s scipy.stats.tests.test_stats::TestCorrPearsonr`, `-s scipy.stats.tests.test_stats::test_kendalltau`).
Typo: those examples should use -t, not -s.
Is there a way to run the tests whose names match a given pattern? For example, I'd like to use the pattern `*ttest_rel*` to run any test that has `ttest_rel` in its name.
Answering my own question: additional arguments given to runtests.py after `--` are passed to the pytest command, and pytest has the option -k to select a substring expression, so something like this works to run just the tests with `ttest_rel` in the test name within the stats module python runtests.py -n -s stats -- -k ttest_rel (The -n is there because I'm running the tests on a previous installation.) Warren
I can hack this by adding the line
python_functions = *ttest_rel*
to pytest.ini, and then comment out that line when I want to run a larger set of tests, but it would be nice if a pattern could be given in the command line.
Warren
participants (2)
-
Matti Picus
-
Warren Weckesser