[SciPy-Dev] Run just the test functions that match a given pattern?

Warren Weckesser warren.weckesser at gmail.com
Sun Apr 19 11:26:28 EDT 2020


On 4/19/20, Warren Weckesser <warren.weckesser at 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
>


More information about the SciPy-Dev mailing list