[TIP] py.test parametrized resources & test selection

holger krekel holger at merlinux.eu
Wed Oct 29 01:26:11 PDT 2014


Hi Wouter,

On Wed, Oct 29, 2014 at 09:16 +0100, Wouter Overmeire wrote:
> Hi,
> 
> 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?

Two options:

- you can run with "-k db_initialized" which should select the
  appropriate tests.  (Or "-k d1" to select just the one parametrized one).
 
- If you run in --verbose mode you get the full ID of each test which
  you can copy and paste to the command line.
  
HTH,
holger


> 
> 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:
> [...snip...]/test_backends.py::test_db_initialized
> (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]
> 
> Wouter

> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python




More information about the testing-in-python mailing list