0
0
PyTesttesting~5 mins

Testpaths configuration in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the testpaths setting in pytest?
The testpaths setting tells pytest which directories or files to look into when searching for tests to run. It helps focus test discovery on specific locations.
Click to reveal answer
beginner
How do you specify multiple directories in testpaths?
You list them as a sequence in the pytest.ini file under testpaths, like:<br>
[pytest]
testpaths = tests integration_tests
Click to reveal answer
beginner
Where do you configure testpaths in a pytest project?
You configure testpaths in the pytest.ini file or other pytest config files like tox.ini or setup.cfg under the [pytest] section.
Click to reveal answer
intermediate
What happens if you do not set testpaths in pytest?
Pytest will search for tests starting from the current directory and all its subdirectories by default, which might include unwanted files or slow down test discovery.
Click to reveal answer
intermediate
Can testpaths include files as well as directories?
Yes, testpaths can include specific test files or directories. Pytest will look for tests only in those specified paths.
Click to reveal answer
What is the main role of testpaths in pytest?
ATo specify where pytest looks for tests
BTo define test execution order
CTo set test timeout values
DTo configure test output format
How do you add multiple directories to testpaths in pytest.ini?
AUse a single string with spaces
BSeparate them with commas
CList each directory on a new line under <code>testpaths</code>
DUse a JSON array
If testpaths is not set, where does pytest look for tests?
AOnly in the root directory
BIn the user's home directory
CIn the current directory and all subdirectories
DIn the system's temp folder
Which file can you NOT use to configure testpaths?
A<code>pytest.ini</code>
B<code>tox.ini</code>
C<code>setup.cfg</code>
D<code>requirements.txt</code>
Can testpaths include individual test files?
ANo, only directories are allowed
BYes, it can include files and directories
COnly files with .pyc extension
DOnly files in the root directory
Explain how to configure pytest to look for tests only in specific folders using testpaths.
Think about the config file and the syntax for listing paths.
You got /4 concepts.
    What are the benefits of using testpaths in a pytest project?
    Consider how limiting search paths helps test runs.
    You got /4 concepts.