Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I select multiple tests on py.test?

Tags:

pytest

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:

  • test_should_connect
  • test_should_execute
  • test_should_return

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 =/

like image 885
Almir Filho Avatar asked Apr 17 '13 18:04

Almir Filho


People also ask

How do I run multiple tests in pytest?

Run Multiple Tests From a Specific File and Multiple Files To run all the tests from all the files in the folder and subfolders we need to just run the pytest command. This will run all the filenames starting with test_ and the filenames ending with _test in that folder and subfolders under that folder.

Is there a way to specify which pytest tests to run from a file?

Running pytestWe can run a specific test file by giving its name as an argument. A specific function can be run by providing its name after the :: characters. Markers can be used to group tests. A marked grouped of tests is then run with pytest -m .


1 Answers

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?

like image 154
hpk42 Avatar answered Nov 02 '22 22:11

hpk42