Challenge - 5 Problems
PyTest Plugin Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Why use plugins in PyTest?
Which of the following best explains why plugins are used to extend PyTest capabilities?
Attempts:
2 left
💡 Hint
Think about how plugins help without modifying the main tool.
✗ Incorrect
Plugins allow adding features and hooks to PyTest, enabling customization and integration without altering PyTest's core code.
❓ Predict Output
intermediate2:00remaining
Output of PyTest with a plugin hook
What will be the output when running this PyTest test with a plugin that implements pytest_runtest_setup hook printing 'Setup called'?
PyTest
def test_example(): assert True
Attempts:
2 left
💡 Hint
The setup hook runs before the test and prints first.
✗ Incorrect
The pytest_runtest_setup hook runs before the test and prints 'Setup called'. Then the test runs and passes, showing '.' and '1 passed'.
❓ assertion
advanced2:00remaining
Correct assertion for plugin-added marker
Given a PyTest plugin adds a marker 'slow' to tests, which assertion correctly checks if a test has this marker?
PyTest
def test_has_marker(request): # Check if 'slow' marker is present pass
Attempts:
2 left
💡 Hint
Use the official PyTest API to get markers.
✗ Incorrect
The correct way is to use get_closest_marker which returns the marker object or None if not found.
🔧 Debug
advanced2:00remaining
Debugging plugin import error in PyTest
A PyTest plugin fails to load with error: ModuleNotFoundError: No module named 'pytest_custom'. What is the most likely cause?
Attempts:
2 left
💡 Hint
ModuleNotFoundError means Python cannot find the module.
✗ Incorrect
This error means the plugin package is missing or not installed in the current Python environment.
❓ framework
expert3:00remaining
How plugins affect PyTest test discovery
Which statement correctly describes how PyTest plugins can influence test discovery?
Attempts:
2 left
💡 Hint
Think about how plugins can change PyTest behavior before tests run.
✗ Incorrect
Plugins can implement hooks like pytest_collect_file to customize test discovery, filtering, or adding new test sources.