0
0
PyTesttesting~20 mins

Addopts for default options in PyTest - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Addopts Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding pytest addopts default behavior

What is the effect of adding --maxfail=2 --disable-warnings to the addopts option in pytest.ini?

APytest will ignore the first 2 failures and show warnings only for errors.
BPytest will run only 2 tests and show all warnings.
CPytest will stop after 2 test failures and suppress all warning messages during test runs.
DPytest will run tests twice and disable all error messages.
Attempts:
2 left
💡 Hint

Think about what --maxfail and --disable-warnings do individually.

Predict Output
intermediate
1:30remaining
Output of pytest with addopts for verbosity

Given the following pytest.ini configuration:

[pytest]
addopts = -v

and a test file test_sample.py with two passing tests, what will be the output style when running pytest?

PyTest
def test_one():
    assert 1 == 1

def test_two():
    assert 2 == 2
APytest will show only dots for each passing test without names.
BPytest will show detailed test names and statuses for each test (verbose output).
CPytest will stop after the first test and show no output.
DPytest will show warnings and errors but no test results.
Attempts:
2 left
💡 Hint

What does the -v option do in pytest?

assertion
advanced
2:00remaining
Correct assertion to verify addopts effect

You have set addopts = --tb=short in pytest.ini. Which assertion correctly verifies that the traceback style is short during test failure?

PyTest
def test_fail():
    assert False
Aassert pytest.config.getoption('tb') == 'short'
Bassert 'short' in pytest.config.getoption('tbstyle')
Cassert '--tb=short' in pytest.config.getoption('addopts')
Dassert 'short' in pytest.config.getoption('tb')
Attempts:
2 left
💡 Hint

Check how to access the traceback style option in pytest.

🔧 Debug
advanced
1:30remaining
Debugging addopts syntax error in pytest.ini

Which addopts line in pytest.ini will cause a syntax error when pytest tries to parse it?

Aaddopts = --maxfail=3 --disable-warnings
Baddopts = --maxfail=3 --disable-warnings --tb=short
Caddopts = --maxfail=3 --tb=short
Daddopts = --maxfail=3 --disable warnings
Attempts:
2 left
💡 Hint

Look carefully at the spacing in the options.

framework
expert
2:30remaining
Effect of addopts on pytest test discovery

If addopts in pytest.ini includes --ignore=tests/integration, what will happen when you run pytest?

APytest will skip all tests inside the <code>tests/integration</code> directory during discovery.
BPytest will only run tests inside <code>tests/integration</code> and ignore others.
CPytest will run all tests but mark those in <code>tests/integration</code> as expected failures.
DPytest will fail to start due to invalid addopts syntax.
Attempts:
2 left
💡 Hint

What does the --ignore option do in pytest?