Skip to content

This repository provides a solution to optimize test parametrization in pytest, focusing on performance improvements for large test suites. By filtering tests within the `pytest_generate_tests` hook based on specified markers or keywords, this approach reduces unnecessary overhead, enhances test execution speed, and improves resource efficiency.

Notifications You must be signed in to change notification settings

omerkarpas/pytest-optimized-parametrization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

pytest-optimized-parametrization


This repository contains a solution to optimize the test parametrization process in pytest, specifically addressing performance issues that arise in large test suites with numerous tests and fixtures. By implementing a filtering mechanism within the pytest_generate_tests hook, this solution ensures that only the relevant tests matching specified markers or keywords are parametrized, significantly reducing unnecessary overhead and improving overall test execution performance.

Key Features

  • Efficient Parametrization: Dynamically parametrize only the tests that match specified markers or keywords, reducing collection time and resource consumption.
  • Customizable Filtering: Easily adjust the filtering mechanism to suit different testing needs and configurations.
  • Enhanced Performance: Focus computational resources on relevant tests, improving test execution speed and developer productivity.
  • Detailed Logging: Comprehensive logging to trace the parametrization process and identify tests that are included or excluded based on markers and keywords.

Contents

  • pytest_generate_tests Hook: A customized implementation of the pytest_generate_tests hook to optimize test parametrization.
  • Helper Functions: Functions to evaluate expressions, check marker presence, and determine if tests should be skipped based on markers or keywords.
  • Examples and Usage: Sample code and usage instructions to demonstrate how to integrate and use the optimized parametrization in your own pytest setup.

Getting Started

  1. Clone the Repository:

    git clone https://github.com/yourusername/pytest-optimized-parametrization.git
  2. Install Dependencies: Ensure you have pytest installed. You can install it via pip if needed:

    pip install pytest
  3. Integrate the Custom Hook: Add the provided pytest_generate_tests hook and helper functions to your pytest configuration by placing them in a conftest.py.

  4. Run Tests with Markers: Use markers to specify which tests to parametrize and run, leveraging the optimized filtering mechanism:

    pytest -m "your_marker"

Contributing

Contributions are welcome! If you have ideas for improvements or find any issues, please open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.


By implementing this solution, you can significantly improve the efficiency and performance of your test suite, ensuring that pytest remains a powerful and scalable tool for your testing needs.

About

This repository provides a solution to optimize test parametrization in pytest, focusing on performance improvements for large test suites. By filtering tests within the `pytest_generate_tests` hook based on specified markers or keywords, this approach reduces unnecessary overhead, enhances test execution speed, and improves resource efficiency.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages