import pytest @pytest.mark.P0 def test_case1(): pass # perform some P0 test for your app def test_case2(): pass def test_case3(): pass class TestClass: def test_case4(self): pass
1. Select to run a specific class
You can select the case you want to run according to the module, class or function of a test case
>pytest -v test_pytest_markers.py::TestClass
2. Select to run a specific test case , suitable for debugging a single test case at the beginning.
pytest -v test_pytest_markers.py::TestClass::test_method
3. Multiple combinations run
>pytest -v test_pytest_markers.py::TestClass test_pytest_markers.py::test_send_http
4. Use -k for keyword matching to run the test case name substring
>pytest -v -k case1 test_pytest_markers.py
Pytest Marker mechanism
5. Use Marker to run
test cases for Pytest, you can add a marker to each test case, for example, when pytest runs, only the test cases with the marker are run, For example @pytest.mark.P0 below.
pytest -v -m "P0" test_pytest_markers.py