Skip to content

Discover Pytest Plugins via Entry Points (pytest11) #75

@benediktziegler

Description

@benediktziegler

Problem Statement

Currently, the scanner uses a hardcoded list of known pytest plugin package names (e.g., pytest_mock, pytest_asyncio, pytest_django, etc.) to identify which packages to scan for fixtures. This approach has several limitations:

  • New or custom plugins are not discovered
  • The list requires manual maintenance
  • Some plugins may be missed if they don't follow naming conventions

Proposed Solution

Replace the hardcoded pytest plugin package names with dynamic discovery via pytest11 entry points in .dist-info/entry_points.txt. This is the standard mechanism pytest itself uses to discover plugins.

Background

The entry_points.txt file in a .dist-info directory looks like:

[pytest11]
plugin_name = package.module:optional_attr
mock = pytest_mock
asyncio = pytest_asyncio.plugin

Each entry in the [pytest11] section registers a pytest plugin module that should be loaded.

Implementation Requirements

Scanner Changes (src/fixtures/scanner.rs)

  1. Add load_plugin_from_entry_point() method to:

    • Read entry_points.txt from .dist-info directories
    • Parse the [pytest11] section
    • Resolve module paths to file paths within site-packages
    • Scan discovered plugin modules for fixtures
  2. Modify scan_pytest_plugins() to:

    • Iterate over ALL .dist-info directories instead of filtering by package name
    • Call load_plugin_from_entry_point() for each dist-info directory
    • Remove or deprecate the hardcoded pytest_packages list

Scope

This issue focuses on discovering plugins installed normally in site-packages. Editable installs (pip install -e) are out of scope and will be addressed in a follow up issue.

Expected Benefits

  1. Automatic discovery: Any properly registered pytest plugin will be discovered
  2. No maintenance: No need to update a hardcoded list when new plugins are released
  3. Custom plugins: User's own pytest plugins are discovered if properly packaged

Testing Requirements

Tests should verify:

  • Entry point parsing and module resolution
  • Fixture discovery from dynamically discovered plugins
  • Handling of malformed or missing entry_points.txt files
  • Packages without pytest11 entry points are not scanned

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions