LambdaTest Community

Find answers, support, and inspiration from other users

Questions
LambdaTest Community
Answered

How does PyTest identify the test files and test methods?

I want to know How does PyTest identify the test files and test methods. Can anyone please provide me help regarding that.

Up Vote Down Vote 0 Votes
Posted 3 months ago

Answers


Executing the pytest command (without mentioning a filename) on the terminal will run all the Python files that have filenames starting with test_* or ending with *_test. These files are automatically identified as test files by the pytest framework.

The framework also mandates that the test methods should start with ‘test’ else the method will not be considered for execution. Below are two mandatory requirements for test code for Selenium testing with Python & pytest.

File naming nomenclature - File name should be test_*.py or *_test.py
Test Method nomenclature - Test method should be of the format test*

These are mandatory requirements as pytest has features built-in to the framework that supports auto-discovery of test modules and test methods (or functions).

Up Vote Down Vote 0 Votes
Posted 2 months ago