0
0
PyTesttesting~20 mins

setup.cfg configuration in PyTest - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
setup.cfg pytest Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of pytest with setup.cfg markers
Given the following setup.cfg configuration and test file, what will be the output when running pytest without any additional options?
PyTest
[pytest]
markers =
    slow: marks tests as slow

# test_sample.py
import pytest

@pytest.mark.slow
def test_slow():
    assert True

def test_fast():
    assert True
ABoth tests are skipped.
BOnly test_fast runs and passes; test_slow is skipped.
CBoth tests run and pass.
Dpytest raises an error due to unknown marker.
Attempts:
2 left
💡 Hint
Markers declared in setup.cfg do not skip tests by default.
assertion
intermediate
2:00remaining
Correct assertion for test selection by keyword
With this setup.cfg snippet, which assertion correctly verifies that only tests marked with 'slow' run when using pytest -m slow?
PyTest
[pytest]
markers =
    slow: marks tests as slow

# test_sample.py
import pytest

@pytest.mark.slow
def test_slow():
    assert True

def test_fast():
    assert True
Aassert 'skipped' in result.stdout
Bassert 'test_fast' in result.stdout and 'test_slow' not in result.stdout
Cassert 'collected 2 items' in result.stdout
Dassert 'test_slow' in result.stdout and 'test_fast' not in result.stdout
Attempts:
2 left
💡 Hint
Using -m slow runs only tests with the slow marker.
🔧 Debug
advanced
2:00remaining
Why does pytest warn about unknown marker despite setup.cfg?
You have this setup.cfg: [pytest] markers = regression: marks regression tests But running tests marked with @pytest.mark.regression still shows a warning about unknown marker. What is the most likely cause?
AThe <code>setup.cfg</code> file is not in the root directory where pytest is run.
BThe marker name in the test code is misspelled as 'regresion'.
Cpytest requires markers to be declared in <code>pytest.ini</code>, not <code>setup.cfg</code>.
DThe test function is missing the <code>@pytest.mark.usefixtures</code> decorator.
Attempts:
2 left
💡 Hint
pytest reads setup.cfg only if it is in the current directory or above.
framework
advanced
2:00remaining
Configuring pytest to ignore warnings via setup.cfg
Which setup.cfg snippet correctly configures pytest to ignore DeprecationWarning during test runs?
A
[pytest]
filterwarnings = ignore::DeprecationWarning
B
[pytest]
ignore_warnings = DeprecationWarning
C
[pytest]
filterwarnings = error::DeprecationWarning
D
[pytest]
warnings_ignore = DeprecationWarning
Attempts:
2 left
💡 Hint
pytest uses filterwarnings option with ignore action.
🧠 Conceptual
expert
3:00remaining
Effect of testpaths in setup.cfg on test discovery
Given this setup.cfg: [pytest] testpaths = tests integration What is the effect of this configuration when running pytest without arguments?
Apytest will discover tests in all directories except 'tests' and 'integration'.
Bpytest will only discover tests inside the 'tests' and 'integration' directories.
Cpytest will ignore the 'tests' and 'integration' directories and discover tests elsewhere.
Dpytest will run tests only in the current directory, ignoring subdirectories.
Attempts:
2 left
💡 Hint
testpaths limits where pytest looks for tests.