0
0
Dockerdevops~20 mins

Running tests in containers in Docker - 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!
💻 Command Output
intermediate
1:30remaining
Output of a Docker test run command
What is the output of running this Docker command to execute tests inside a container?
Docker
docker run --rm -v $(pwd):/app -w /app python:3.12 python -m unittest discover tests
AError: No such file or directory: tests
BRan 5 tests in 0.002s\n\nOK
CSyntaxError: invalid syntax in test file
DPermission denied while accessing /app
Attempts:
2 left
💡 Hint
The command mounts the current directory and runs Python tests inside the container.
🧠 Conceptual
intermediate
1:00remaining
Understanding Docker test container isolation
Why is it beneficial to run tests inside Docker containers instead of directly on the host machine?
AIt ensures tests run in a consistent environment regardless of the host setup.
BIt makes tests run faster than on the host machine always.
CIt automatically fixes bugs in the test code.
DIt disables network access for all tests by default.
Attempts:
2 left
💡 Hint
Think about environment differences between machines.
Configuration
advanced
2:00remaining
Dockerfile for running tests with environment variables
Which Dockerfile snippet correctly sets an environment variable and runs tests using pytest inside the container?
A
FROM python:3.12
ENV TEST_ENV=ci
WORKDIR /app
COPY . .
RUN pip install pytest
CMD ["pytest", "tests"]
B
FROM python:3.12
WORKDIR /app
COPY . .
RUN pip install pytest
CMD ["TEST_ENV=ci pytest tests"]
C
FROM python:3.12
WORKDIR /app
COPY . .
RUN pip install pytest
ENV TEST_ENV=ci
CMD ["pytest", "tests"]
D
FROM python:3.12
WORKDIR /app
COPY . .
RUN pip install pytest
CMD pytest tests
ENV TEST_ENV=ci
Attempts:
2 left
💡 Hint
Environment variables should be set before the command runs.
Troubleshoot
advanced
1:30remaining
Diagnosing test failures in Docker container
You run tests inside a Docker container but get this error: "ModuleNotFoundError: No module named 'requests'". What is the most likely cause?
AThe container does not have network access to download tests.
BThe tests are running on the host, not inside the container.
CThe Dockerfile is missing the WORKDIR instruction.
DThe 'requests' package is not installed inside the container.
Attempts:
2 left
💡 Hint
Think about Python dependencies inside containers.
🔀 Workflow
expert
2:30remaining
Best workflow to run tests in CI with Docker
Which sequence of steps is the best workflow to run automated tests in a CI pipeline using Docker containers?
A4,2,1,3
B1,4,2,3
C4,1,2,3
D1,2,4,3
Attempts:
2 left
💡 Hint
Consider the logical order of preparing images, running tests, and pushing images.