0
0
PyTesttesting~5 mins

Addopts for default options in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the addopts setting in pytest?
The addopts setting in pytest allows you to specify default command-line options that pytest will use every time it runs. This helps avoid typing common options repeatedly.
Click to reveal answer
beginner
Where do you add the addopts setting to configure default pytest options?
You add the addopts setting in the pytest.ini file or other pytest configuration files like tox.ini or setup.cfg.
Click to reveal answer
beginner
Example: How to set pytest to always show detailed test output by default using addopts?
In pytest.ini, add:<br>
[pytest]
addopts = -v
<br>This makes pytest run with verbose output every time without typing -v.
Click to reveal answer
intermediate
Can command-line options override addopts settings?
Yes. Options given directly on the command line when running pytest will override the defaults set in addopts.
Click to reveal answer
intermediate
Why is using addopts helpful in a team environment?
Using addopts ensures everyone runs pytest with the same default options, leading to consistent test runs and easier debugging.
Click to reveal answer
Where is the addopts setting typically placed to set default pytest options?
AIn the <code>pytest.ini</code> file
BInside each test function
CIn the Python environment variables
DIn the test script comments
What happens if you run pytest with a command-line option that conflicts with addopts?
A<code>addopts</code> always overrides command-line options
BBoth options are ignored
Cpytest throws an error
DThe command-line option overrides <code>addopts</code>
Which of these is a valid use of addopts in pytest.ini?
A[pytest] addopts = import pytest
B[pytest] addopts = test_function()
C[pytest] addopts = -v --maxfail=2
D[pytest] addopts = def test(): pass
Why might you want to use addopts instead of typing options every time?
ATo ensure consistent test runs and save time
BTo make tests run slower
CTo disable all tests
DTo avoid writing test code
Which file can also contain addopts besides pytest.ini?
Arequirements.txt
Btox.ini
CREADME.md
Dsetup.py
Explain how to use addopts to set default pytest options and why it is useful.
Think about how to save time and keep test runs consistent.
You got /5 concepts.
    Describe a scenario where using addopts improves teamwork in testing.
    Consider how shared settings help a team.
    You got /4 concepts.