Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion rewriting issue with editable-installed plugins #11783

Open
bluetech opened this issue Jan 6, 2024 · 0 comments
Open

Assertion rewriting issue with editable-installed plugins #11783

bluetech opened this issue Jan 6, 2024 · 0 comments
Labels
topic: rewrite related to the assertion rewrite mechanism type: bug problem that needs to be addressed

Comments

@bluetech
Copy link
Member

bluetech commented Jan 6, 2024

Problem

When I look into/debug external plugins, my workflow is:

  • Create a venv
  • Run pip install -e . (this is with a recent pip and setuptools backend, so is using "new style" PEP 660 editable installs. editable_mode=strict doesn't seem to make a difference)
  • Run pytest

While doing this for several plugins recently (e.g. pytest-asyncio), I've noticed pytest issues a warning:

../../../../home/ran/src/pytest/src/_pytest/config/__init__.py:759
  /home/ran/src/pytest/src/_pytest/config/__init__.py:759: PytestAssertRewriteWarning: Module already imported so cannot be rewritten: pytest_asyncio
    self.import_plugin(import_spec)

Analysis

This is my understanding of why this happens:

  • pytest's assertion rewriting requires that a module be marked for rewrite before it is imported.
  • For external plugins this is done by the _mark_plugins_for_rewrite function.
  • This function iterates over all files of all installed distributions which have a pytest11 entry point, and marks their modules for rewrite if necessary.

This ends up now working with my workflow because the distribution.files doesn't contain any of the actual package python files. Relevant issues: python/cpython#96144 pypa/packaging-problems#620

Currently there is no solution from the packaging side. It might be possible to add a workaround on the pytest side, I'm not sure.

@bluetech bluetech added type: bug problem that needs to be addressed topic: rewrite related to the assertion rewrite mechanism labels Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: rewrite related to the assertion rewrite mechanism type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

1 participant