Almir Filho
Almir Filho

Reputation: 4677

How can I select multiple tests on py.test?

I'm familiar with the command py.test -k string for select all tests that contains the string in their name and run it.

What I want is to select tests with more than one string parameter like an OR logical selection. For example, let's say that I have 3 tests:

And let's say I just want to run test_should_connect and test_should_return only. I've looked for an answer in py.test documentation, and to do that I should use the following command:

py.test -k "connect or return"

But, this doesn't work =/

Upvotes: 7

Views: 7784

Answers (2)

treddy
treddy

Reputation: 2921

-k should work just fine here again these days (with newer pytest)--if you want a full-blown regex you can also use pytest-regex (I just released it on PyPI) and do something like this: pytest -v --regex ".*test_(connect|return)$"

which will run tests where the regex matches the node id, where node id looks like:

path/to/test_module.py::TestClass::test_name[parameter_value]

A discussion for potential inclusion in pytest proper is happening here, but not sure where it will land: https://github.com/pytest-dev/pytest/issues/11024

Upvotes: 0

hpk42
hpk42

Reputation: 23571

py.test -k "connect or return" should work. Are you using pytest==2.3.4? Could you paste the output from "py.test" otherwise along with the tests?

Upvotes: 14

Related Questions