Bird
Raised Fist0
PyTesttesting~20 mins

Installing and managing plugins in PyTest - Practice Exercises

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
pytest Plugin Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding pytest plugin installation
Which command correctly installs the pytest plugin named pytest-cov using pip?
Apip install pytest-cov
Bpytest install pytest-cov
Cpip pytest install pytest-cov
Dinstall pytest-cov
Attempts:
2 left
💡 Hint
Use pip to install Python packages.
❓ Predict Output
intermediate
2:00remaining
Output of pytest plugin list command
What is the expected output when running pytest --trace-config after installing the pytest-mock plugin?
ARuns tests without showing any plugin information
BShows an error: unknown option '--trace-config'
CLists all loaded plugins including pytest-mock with their configuration files
DOnly lists built-in pytest plugins, excluding pytest-mock
Attempts:
2 left
💡 Hint
The --trace-config option shows plugin loading details.
❓ assertion
advanced
2:00remaining
Correct assertion to verify plugin availability
Which assertion correctly checks if the pytest-cov plugin is active in a pytest session object named session?
Aassert 'cov' in session.config.pluginmanager.get_plugins()
Bassert 'pytest-cov' in session.plugins
Cassert session.has_plugin('pytest-cov')
Dassert session.config.pluginmanager.has_plugin('cov')
Attempts:
2 left
💡 Hint
Use pluginmanager's has_plugin('cov') to check for the plugin.
🔧 Debug
advanced
2:00remaining
Debugging plugin import error
You installed pytest-html but get an ImportError when running pytest. Which option explains the most likely cause?
Apytest-html requires a special license key to work
BThe plugin was installed in a different Python environment than the one running pytest
Cpytest-html is incompatible with pytest versions above 5.0
Dpytest-html must be imported manually in every test file
Attempts:
2 left
💡 Hint
Check your Python environments and where packages are installed.
❓ framework
expert
3:00remaining
Managing plugin versions in pytest
You want to ensure your project always uses pytest-cov version 4.0.0 exactly. Which is the best way to enforce this in your project?
ASpecify 'pytest-cov==4.0.0' in your requirements.txt or pyproject.toml and use a virtual environment
BInstall pytest-cov globally with pip install pytest-cov==4.0.0
CAdd 'pytest-cov>=4.0.0' in your setup.cfg without a virtual environment
DManually check plugin version before each test run and reinstall if needed
Attempts:
2 left
💡 Hint
Use dependency files and isolated environments for consistent versions.

Practice

(1/5)
1. What is the primary purpose of plugins in pytest?
easy
A. To add extra features without changing pytest's core code
B. To replace pytest's core functionality completely
C. To uninstall pytest from the system
D. To write test cases automatically

Solution

  1. Step 1: Understand what plugins do in pytest

    Plugins add new features or extend existing ones without modifying pytest's main code.
  2. Step 2: Compare options with this understanding

    Only To add extra features without changing pytest's core code correctly describes this purpose; others describe unrelated or incorrect actions.
  3. Final Answer:

    To add extra features without changing pytest's core code -> Option A
  4. Quick Check:

    Plugins extend features = C [OK]
Hint: Plugins add features without changing core code [OK]
Common Mistakes:
  • Thinking plugins replace pytest core
  • Confusing plugins with uninstall commands
  • Believing plugins auto-write tests
2. Which command correctly installs a pytest plugin named pytest-cov?
easy
A. pytest install pytest-cov
B. pip install pytest-cov
C. pip uninstall pytest-cov
D. pytest --install pytest-cov

Solution

  1. Step 1: Identify the standard way to install Python packages

    Python packages, including pytest plugins, are installed using pip install package-name.
  2. Step 2: Match the command to install pytest-cov

    Only pip install pytest-cov uses the correct pip install syntax; others are invalid commands.
  3. Final Answer:

    pip install pytest-cov -> Option B
  4. Quick Check:

    Use pip install for plugins = A [OK]
Hint: Use 'pip install plugin-name' to add plugins [OK]
Common Mistakes:
  • Using pytest commands to install plugins
  • Confusing uninstall with install
  • Adding extra flags not supported
3. What will be the output of the command pytest --trace-config when run in a project with plugins installed?
medium
A. The pytest version number only
B. An error saying the command is invalid
C. A list of all test cases found in the project
D. A list showing all active plugins and their configuration details

Solution

  1. Step 1: Understand the purpose of pytest --trace-config

    This command shows detailed information about pytest's configuration, including active plugins and their settings.
  2. Step 2: Evaluate the options based on this purpose

    A list showing all active plugins and their configuration details matches the expected output; others describe unrelated outputs or errors.
  3. Final Answer:

    A list showing all active plugins and their configuration details -> Option D
  4. Quick Check:

    --trace-config shows plugins = A [OK]
Hint: Use --trace-config to see active plugins and settings [OK]
Common Mistakes:
  • Expecting test case list from --trace-config
  • Thinking it shows version only
  • Assuming command causes error
4. You tried to uninstall a pytest plugin using pip uninstall pytest-cov but the plugin still appears in pytest --trace-config. What is the most likely cause?
medium
A. The plugin cannot be uninstalled once installed
B. You need to restart your computer to complete uninstallation
C. You have multiple Python environments and uninstalled in the wrong one
D. The command should be pytest uninstall pytest-cov

Solution

  1. Step 1: Understand Python environments and plugin installation

    Python packages can be installed in different environments (like virtualenvs). Uninstalling in one environment doesn't affect others.
  2. Step 2: Analyze why plugin still appears after uninstall

    If the plugin still shows, likely it was uninstalled in a different environment than the one pytest uses.
  3. Final Answer:

    You have multiple Python environments and uninstalled in the wrong one -> Option C
  4. Quick Check:

    Multiple envs cause uninstall confusion = B [OK]
Hint: Check Python environment when uninstalling plugins [OK]
Common Mistakes:
  • Believing plugins can't be uninstalled
  • Thinking restart is needed
  • Using wrong uninstall command
5. You want to install a plugin and ensure it is active for your pytest runs without affecting other projects. Which approach is best?
hard
A. Create a virtual environment, activate it, then run pip install plugin-name
B. Install the plugin globally using pip install plugin-name without a virtual environment
C. Copy plugin files manually into your project folder
D. Run pytest --install plugin-name inside your project

Solution

  1. Step 1: Understand isolation of plugin installations

    Using a virtual environment keeps plugin installations isolated per project, avoiding conflicts.
  2. Step 2: Evaluate installation methods

    Create a virtual environment, activate it, then run pip install plugin-name uses a virtual environment and pip install, which is best practice. Others either install globally or use invalid methods.
  3. Final Answer:

    Create a virtual environment, activate it, then run pip install plugin-name -> Option A
  4. Quick Check:

    Use virtualenv for isolated installs = D [OK]
Hint: Use virtualenv to isolate plugin installs per project [OK]
Common Mistakes:
  • Installing plugins globally causing conflicts
  • Trying to copy plugin files manually
  • Using invalid pytest commands to install
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard