0
0
PyTesttesting~8 mins

Installing and managing plugins in PyTest - Framework Setup Guide

Choose your learning style9 modes available
Framework Mode - Installing and managing plugins
Folder Structure of a Pytest Project
pytest-project/
├── tests/
│   ├── test_example.py
│   └── test_login.py
├── plugins/
│   └── custom_plugin.py
├── conftest.py
├── pytest.ini
└── requirements.txt
  
Test Framework Layers
  • Tests: Located in tests/ folder, contains test scripts like test_example.py.
  • Plugins: Custom plugins placed in plugins/ folder or installed via pip.
  • Configuration: pytest.ini for plugin settings and options.
  • Fixtures & Hooks: Defined in conftest.py to share setup/teardown and extend pytest behavior.
  • Dependencies: Managed in requirements.txt including plugins.
Configuration Patterns for Plugins

Use pytest.ini to enable and configure plugins. Example:

[pytest]
addopts = -ra -q
markers =
    smoke: quick smoke tests
    regression: full regression suite

# Plugin specific options
filterwarnings = ignore::DeprecationWarning
  

Install plugins via pip install and list them in requirements.txt:

pytest
pytest-cov
pytest-xdist
  

Use conftest.py to register hooks or fixtures that plugins can use or extend.

Test Reporting and CI/CD Integration
  • Use plugins like pytest-html or pytest-cov for HTML reports and coverage reports.
  • Configure reports in pytest.ini or command line options.
  • Integrate pytest runs in CI/CD pipelines (GitHub Actions, Jenkins) by installing plugins and running tests with reporting options.
  • Example command for CI: pytest --html=report.html --self-contained-html
Best Practices for Installing and Managing Plugins
  • Keep plugins listed in requirements.txt for easy environment setup.
  • Use pytest.ini to centralize plugin configurations and avoid command line clutter.
  • Write custom plugins in plugins/ folder and register them via conftest.py if needed.
  • Regularly update plugins to get bug fixes and new features.
  • Test plugin compatibility when upgrading pytest or other dependencies.
Self Check

Where would you add a new custom plugin that provides extra test reporting features in this framework structure?

Key Result
Manage pytest plugins by installing via pip, configuring in pytest.ini, and organizing custom plugins in a dedicated folder with conftest.py hooks.