Challenge - 5 Problems
Docker Test Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pytest run inside Docker container
Consider a Docker container running a pytest suite with the following test file
What will be the result of running
test_sample.py:def test_addition():
assert 2 + 3 == 5
def test_subtraction():
assert 5 - 3 == 1What 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
Attempts:
2 left
💡 Hint
Check the assertions carefully for correctness.
✗ Incorrect
The first test passes because 2 + 3 equals 5. The second test fails because 5 - 3 equals 2, not 1.
❓ locator
intermediate1: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?Attempts:
2 left
💡 Hint
Inside Docker, absolute paths are more reliable if you know the working directory.
✗ Incorrect
Using the absolute path
/app/tests/test_api.py ensures pytest finds the test file regardless of the current working directory inside the container.❓ assertion
advanced1:30remaining
Assertion outcome in Docker pytest log
Inside a Docker container, a pytest test contains:
What will be the assertion outcome when running pytest inside Docker?
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'
Attempts:
2 left
💡 Hint
Check the string method and expected value carefully.
✗ Incorrect
The
upper() method converts 'hello' to 'HELLO', so the assertion is true and test passes.🔧 Debug
advanced2:00remaining
Debugging pytest failure inside Docker
A pytest test inside Docker fails with:
What is the most likely cause?
FileNotFoundError: [Errno 2] No such file or directory: '/data/input.txt'
What is the most likely cause?
Attempts:
2 left
💡 Hint
FileNotFoundError means the file path is invalid or file is missing.
✗ Incorrect
The error indicates the test tries to open a file that does not exist inside the container's filesystem.
❓ framework
expert3: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?
- 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?
Attempts:
2 left
💡 Hint
Think about isolation, parallelism, and sharing results between container and host.
✗ Incorrect
Docker Compose can orchestrate multiple containers for parallel test runs. Mounting a shared volume allows test reports to be accessible on the host.