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

Export builtin pytest fixtures #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

septatrix
Copy link

I thought this should work but I encounter ERROR test_builtin_fixture_aliases.py - KeyError: 'reexport_capfd' when running the added test...

Fixes #1

@tristan
Copy link
Owner

tristan commented Nov 26, 2024

The problem is because the fixtures in that module are not loaded by the fixture manager at the time the pytest_pycollect_makeitem method is run for our AnnotatedFixturePlugin.

This was also a problem for fixtures using the @pytest_annotated.fixture that I worked around using importlib in AnnotatedFixturePlugin._resolve_from_type to import the module and pass it to the fixture manager to parse.

Here is a similar work around for this problem that works.

diff --git a/src/pytest_annotated/__init__.py b/src/pytest_annotated/__init__.py
index 234ab3b..e5d5225 100644
--- a/src/pytest_annotated/__init__.py
+++ b/src/pytest_annotated/__init__.py
@@ -100,6 +100,11 @@ class AnnotatedFixturePlugin:
         if self.fm is None:
             self.fm = self.pm.get_plugin("funcmanage")
             assert self.fm is not None
+            builtins_mod = importlib.import_module("pytest_annotated.builtins")
+            self.fm.parsefactories(
+                builtins_mod,
+                None,
+            )

I expect there is probably a better way to deal with these issues, but I haven't had the time to figure it out yet, so would be fine accepting this as a solution for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support builtin pytest fixtures
2 participants