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

Add support for pytest fixtures from local pytest plugins. #1907

Merged

Conversation

moser
Copy link
Contributor

@moser moser commented Jan 31, 2023

I like to structure my pytest fixtures in files separate from conftest.py. The pytest docs advise to include those modules containing fixtures as plugin modules, by giving the fully qualified names as strings in an array assinged to pytest_plugins in the conftest.py.

In this PR, I propose adding the modules from the above-mentioned list to the fixture source modules for better completion and type inference.

I guess that my approach in _load_pytest_plugins is a bit crude and could use some feedback and error handling. Can you give me feedback on this?

@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (11280ef) 94.45% compared to head (c4815c9) 94.46%.

❗ Current head c4815c9 differs from pull request most recent head 6982a49. Consider uploading reports for the commit 6982a49 to get more accurate results

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1907   +/-   ##
=======================================
  Coverage   94.45%   94.46%           
=======================================
  Files          80       80           
  Lines       11917    11932   +15     
=======================================
+ Hits        11256    11271   +15     
  Misses        661      661           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@davidhalter
Copy link
Owner

Hmm good point. I feel like generally you could just infer instead of goto and if a list is inferred infer the inner list elements. That's probably a bit more "solid".

So the order is infer(), probably something like py__iter__?, infer()? each element and then probably check with get_str_or_none(value) if a value is a valid string that you could use.

@moser
Copy link
Contributor Author

moser commented Jan 23, 2024

@davidhalter
I tried to improve on this. Can you have another look?

@moser moser force-pushed the support-fixtures-from-pytest-plugins branch from e1ed8b2 to 9b8cece Compare January 23, 2024 19:54
@davidhalter
Copy link
Owner

@moser Thanks! This looks generally good. It's still marked as a draft. So you might want to finish whatever you want to do and then I'll merge.

@moser moser marked this pull request as ready for review January 24, 2024 12:11
@moser
Copy link
Contributor Author

moser commented Jan 25, 2024

@davidhalter Ready from my side :-)

jedi/plugins/pytest.py Show resolved Hide resolved
@davidhalter
Copy link
Owner

Thanks a lot Martin, good stuff!

@davidhalter davidhalter merged commit 740b474 into davidhalter:master Jan 26, 2024
114 checks passed
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.

3 participants