Introduction
In this post, we will explore some useful command line options for running python unit tests.
Running Selective Test File
Assumming you have lot of tests written, and is in seperate files.
To run only tests within a particular file, you just pass the path to that file only.
pytest <path_to_pytest_file>Running Selective Test case across
Many times, you may want tp run only one test case across your pool of test cases. You would want to run it by name.
pytest -k <test_name>Note: It will run all those test cases where this test_name is occurring. It works kind of `string contains’.
So if your test names are:
test_check_1
test_check_2
test_check_3
test_check_10
test_check_12And, if you run
pytest -k test_check1It will run following test cases:
test_check_1
test_check_10
test_check_12Print console statements
You may have some print statements in between and want to know the output.
pytest -sYou can use it with -k option as well.
pytest -k check_1 -sEnable Logging in Pytest
Often times, the Python logging does not come in pytest. To enable this,
pytest --log-cli-level=INFO
pytest --log-cli-level=INFO -k check_1 -s












