0
0
PyTesttesting~20 mins

pyproject.toml configuration in PyTest - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pytest Configuration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of pytest with custom testpaths in pyproject.toml
Given this pyproject.toml configuration, what will pytest discover and run?
PyTest
[tool.pytest.ini_options]
testpaths = ["tests/integration", "tests/unit"]
APytest runs tests in all folders including 'tests/integration' and 'tests/unit'.
BPytest runs tests in all folders except 'tests/integration' and 'tests/unit'.
CPytest runs tests only in the root folder, ignoring subfolders.
DPytest runs tests only in 'tests/integration' and 'tests/unit' folders.
Attempts:
2 left
💡 Hint
The testpaths option limits where pytest looks for tests.
assertion
intermediate
2:00remaining
Correct assertion for pytest capturing output
You want to check that your function prints 'Hello World' when run. Which pytest assertion correctly tests this using capsys?
PyTest
def greet():
    print("Hello World")

def test_greet(capsys):
    greet()
    captured = capsys.readouterr()
    # Which assertion below is correct?
Aassert captured.err == "Hello World\n"
Bassert captured.out == "Hello World"
Cassert captured.out == "Hello World\n"
Dassert captured.out.contains("Hello World")
Attempts:
2 left
💡 Hint
Remember print adds a newline character at the end.
locator
advanced
2:00remaining
Identify the correct pytest marker configuration in pyproject.toml
Which pyproject.toml snippet correctly registers a custom marker named 'slow' with a description?
A
[tool.pytest.ini_options]
markers = "slow: marks tests as slow to run"
B
[tool.pytest.ini_options]
markers = ["slow: marks tests as slow to run"]
C
[tool.pytest.ini_options]
markers = {slow = "marks tests as slow to run"}
D
[tool.pytest.ini_options]
markers = slow: marks tests as slow to run
Attempts:
2 left
💡 Hint
Markers must be a list of strings with 'name: description' format.
🔧 Debug
advanced
2:00remaining
Why does pytest ignore tests in a subfolder despite pyproject.toml settings?
You set testpaths = ["tests"] in pyproject.toml, but pytest does not find tests in tests/api. What is the most likely cause?
AThe test files in <code>tests/api</code> do not start with 'test_' or end with '_test.py'.
BThe <code>pyproject.toml</code> file is not in the project root directory.
CThe <code>tests/api</code> folder lacks an __init__.py file, so pytest skips it.
DPytest requires explicit inclusion of subfolders in <code>testpaths</code>.
Attempts:
2 left
💡 Hint
Pytest discovers tests by file name patterns by default.
framework
expert
2:00remaining
Effect of adding 'addopts' in pyproject.toml on pytest runs
Given this pyproject.toml snippet, what is the effect of the addopts option when running pytest?
PyTest
[tool.pytest.ini_options]
addopts = "-v --maxfail=2"
APytest runs in verbose mode and stops after 2 test failures.
BPytest runs with 2 workers in parallel and verbose output.
CPytest runs with verbose output and retries failed tests twice.
DPytest runs with maximum 2 tests executed and verbose output.
Attempts:
2 left
💡 Hint
The --maxfail option limits how many failures stop the test run.