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 test using Docker container fixture
What is the output of this pytest test when using the Docker container fixture that starts a Redis container and sets a key?
PyTest
import pytest import redis @pytest.fixture(scope='module') def redis_container(docker_ip, docker_services): port = docker_services.port_for('redis', 6379) client = redis.Redis(host=docker_ip, port=port) docker_services.wait_until_responsive( timeout=30.0, pause=0.1, check=lambda: client.ping()) return client def test_redis_set_get(redis_container): redis_container.set('testkey', 'value') result = redis_container.get('testkey') assert result == b'value' print(result)
Attempts:
2 left
💡 Hint
The fixture waits until Redis is responsive before returning the client.
✗ Incorrect
The fixture starts a Redis container and waits until it responds to ping. The test sets a key and retrieves it, expecting the byte string b'value'. The assertion passes and the value is printed.
❓ assertion
intermediate1:30remaining
Correct assertion for checking HTTP response in Dockerized test
You run a test against a web service inside a Docker container. Which assertion correctly verifies the HTTP status code is 200?
PyTest
response = client.get('http://localhost:8080/api/data')Attempts:
2 left
💡 Hint
Check the attribute name for status code in the response object.
✗ Incorrect
The correct attribute for HTTP status code in most Python HTTP clients is 'status_code'. Using 'is' for integer comparison is not recommended.
🔧 Debug
advanced2:00remaining
Debugging Docker container test failure due to port conflict
A pytest test using a Docker container fails with an error indicating the port 5432 is already in use. What is the most likely cause?
Attempts:
2 left
💡 Hint
Port conflicts happen when two services try to use the same port on the host.
✗ Incorrect
Port 5432 is the default PostgreSQL port. If another process uses it, Docker cannot bind the container port to the host port, causing failure.
❓ framework
advanced1:30remaining
Choosing the best pytest plugin for Docker container management
Which pytest plugin is designed specifically to manage Docker containers lifecycle during tests?
Attempts:
2 left
💡 Hint
Look for a plugin name that includes 'docker'.
✗ Incorrect
pytest-docker helps start and stop Docker containers during pytest runs, making integration testing easier.
🧠 Conceptual
expert2:00remaining
Why use test containers in integration testing?
What is the main advantage of using test containers with Docker in integration testing?
Attempts:
2 left
💡 Hint
Think about environment consistency and isolation.
✗ Incorrect
Test containers run real service instances in isolated Docker containers, ensuring tests run in environments similar to production, improving reliability.