0
0
PyTesttesting~20 mins

Docker-based test execution in PyTest - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Test Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of pytest run inside Docker container
Consider a Docker container running a pytest suite with the following test file test_sample.py:
def test_addition():
    assert 2 + 3 == 5

def test_subtraction():
    assert 5 - 3 == 1

What will be the result of running pytest inside the container?
PyTest
def test_addition():
    assert 2 + 3 == 5

def test_subtraction():
    assert 5 - 3 == 1
A2 passed
B0 tests collected
C2 failed
D1 passed, 1 failed
Attempts:
2 left
💡 Hint
Check the assertions carefully for correctness.
locator
intermediate
1:30remaining
Best locator for pytest test file in Docker context
You want to run pytest inside a Docker container. Which file path locator is best to specify the test file test_api.py located in the /app/tests/ directory inside the container?
A./tests/test_api.py
B/app/tests/test_api.py
C/tests/test_api.py
Dtests/test_api.py
Attempts:
2 left
💡 Hint
Inside Docker, absolute paths are more reliable if you know the working directory.
assertion
advanced
1:30remaining
Assertion outcome in Docker pytest log
Inside a Docker container, a pytest test contains:
def test_string():
    result = 'hello'.upper()
    assert result == 'HELLO'

What will be the assertion outcome when running pytest inside Docker?
PyTest
def test_string():
    result = 'hello'.upper()
    assert result == 'HELLO'
ATest raises TypeError
BTest fails with AssertionError
CTest passes
DTest is skipped
Attempts:
2 left
💡 Hint
Check the string method and expected value carefully.
🔧 Debug
advanced
2:00remaining
Debugging pytest failure inside Docker
A pytest test inside Docker fails with:
FileNotFoundError: [Errno 2] No such file or directory: '/data/input.txt'

What is the most likely cause?
AThe file /data/input.txt is missing inside the Docker container
BDocker container has no network access
CThe test code has a syntax error
Dpytest is not installed in the container
Attempts:
2 left
💡 Hint
FileNotFoundError means the file path is invalid or file is missing.
framework
expert
3:00remaining
Choosing Docker test execution strategy for pytest
You want to run pytest tests inside Docker with these requirements:
- Tests must run in isolated containers
- Test results should be collected on host machine
- Tests should run in parallel

Which Docker strategy best fits these requirements?
AUse Docker Compose to spin up multiple containers running pytest in parallel, mounting a shared volume for test reports
BRun pytest directly on host without Docker for faster execution
CUse a single Docker container running pytest sequentially with no volume mounts
DRun pytest inside Docker but do not collect test reports
Attempts:
2 left
💡 Hint
Think about isolation, parallelism, and sharing results between container and host.