简体   繁体   中英

How can I run several test files with Pytest?

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?

Just add files that you want to run as positional arguments, eg:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM