Home > Software design >  How can I run several test files with Pytest?
How can I run several test files with Pytest?

Time:08-11

I have a pytest project and a want to run tests from TWO python files. The project structure looks like this: at the root of the project there is a "tests" folder, it contains several folders "test_api1", "test_api2", "test_api3", each of them contains conftest.py and a test file.

tests:

  • test_api1: conftest.py, test_api_1
  • test_api2: conftest.py, test_api_2
  • test_api3: conftest.py, test_api_3

Usually I run tests like this

python -m pytest -vs -k tests (if I want to run all tests from tests directory)

or like this

python -m pytest -vs -k test_api1.py (if I want to run a certain test).

But now I want to run tests from TWO certain files test_api1.py and test_api1.py. How can I do that?

CodePudding user response:

Just add files that you want to run as positional arguments, e.g.:

python -m pytest -vs tests/test_api1.py tests/test_api2.py test_apiN.py

NOTE: you need to run pytest without -k flag and hence use paths to the files instead of just filenames.

  • Related