[TIP] py.test parametrized resources & test selection

Wouter Overmeire lodagro at gmail.com
Wed Oct 29 01:16:30 PDT 2014


The py.test documentation has a nice example on deferring the setup of
parametrized resources http://pytest.org/latest/example/parametrize.html.

Suppose i added an extra test in the test_backends.py file.and collect the
test. So far so good.

collected 3 items
<Module 'test_backends.py'>
  <Function 'test_db_initialized[d1]'>
  <Function 'test_db_initialized[d2]'>
  <Function 'test_something_else'>

Running only 'test_something_else' works fine, but how can i run only the
test_db_initialized[*] tests? Or only one of the test_db_initialized[*]
tests, without adding a command line parameter and changing
pytest_generate_tests accordingly?

py.test --collect-only test_backends.py::test_db_initialized
================ test session starts
platform linux2 -- Python 2.7.5 -- py-1.4.26 -- pytest-2.6.4
plugins: cov
collecting 3 itemsERROR: not found:
(no name '[...snip...]/test_backends.py::test_db_initialized' in any of
[<Module 'test_backends.py'>])

py.test --collect-only test_backends.py::test_db_initialized[d1]
zsh: no matches found: test_backends.py::test_db_initialized[d1]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20141029/895c338e/attachment.html>

More information about the testing-in-python mailing list