Pytest Tutorial
Selected Reading
- Pytest - Discussion
- Pytest - Useful Resources
- Pytest - Quick Guide
- Pytest - Conclusion
- Pytest - Summary
- Test Execution Results in XML
- Pytest - Run Tests in Parallel
- Stop Test Suite after N Test Failures
- Pytest - Xfail/Skip Tests
- Pytest - Parameterizing Tests
- Pytest - Conftest.py
- Pytest - Fixtures
- Pytest - Grouping the Tests
- Substring Matching of Test Names
- Execute a Subset of Test Suite
- Pytest - File Execution
- Pytest - Starting With Basic Test
- Identifying Test files and Functions
- Pytest - Environment Setup
- Pytest - Introduction
- Pytest - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Substring Matching of Test Names
Substring Matching of Test Names
To execute the tests containing a string in its name we can use the following syntax −
pytest -k <substring> -v
-k <substring> represents the substring to search for in the test names.
Now, run the following command −
pytest -k great -v
This will execute all the test names having the word ‘great’ in its name. In this case, they are test_greater() and test_greater_equal(). See the result below.
test_compare.py::test_greater FAILED test_compare.py::test_greater_equal PASSED ============================================== FAILURES ============================================== ____________________________________________ test_greater ____________________________________________ def test_greater(): num = 100 > assert num > 100 E assert 100 > 100 test_compare.py:3: AssertionError ========================== 1 failed, 1 passed, 3 deselected in 0.07 seconds ==========================
Here in the result, we can see 3 tests deselected. This is because those test names do not contain the word great in them.
Note − The name of the test function should still start with ‘test’.
Advertisements