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

Provide for including fixtures from common location [improvement] #3625

Open
astraw38 opened this issue Jun 27, 2018 · 7 comments
Open

Provide for including fixtures from common location [improvement] #3625

astraw38 opened this issue Jun 27, 2018 · 7 comments
Labels
topic: fixtures anything involving fixtures directly or indirectly type: enhancement new feature or API change, should be merged into features branch

Comments

@astraw38
Copy link

It'd be very convenient to have a method similar to pytest_plugins = ['path.to.plugin'], but purely for fixture inclusion.

Reasoning:

  • You can move common fixtures to a parent conftest.py, but that can lead to exceptionally large conftest.py files in larger projects
  • Would let you keep similar fixtures grouped together for common imports/functionality
  • You can import fixtures from other locations, but if you don't directly reference them, they are seen as 'unused' by most linters.
@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #1050 (provide dependency-tested autouse fixtures), #3351 (Is there a way to provide mark with fixture params), #1376 (allow fixtures to provide extra info when a test fails), #2502 (How to provide fixture parameters at test level?), and #1216 (Provide a way to nicely control fixture execution order ).

@pytestbot pytestbot added platform: mac mac platform-specific problem type: enhancement new feature or API change, should be merged into features branch labels Jun 27, 2018
@nicoddemus
Copy link
Member

Thanks @astraw38,

You can move common fixtures to a parent conftest.py, but that can lead to exceptionally large conftest.py files in larger projects

Here's a solution to this problem: #3582 (comment)

IMHO this is enough to which I think fits your requirements 1 and 2. What do you think?

@nicoddemus nicoddemus added topic: fixtures anything involving fixtures directly or indirectly and removed platform: mac mac platform-specific problem labels Jun 27, 2018
@astraw38
Copy link
Author

Importing isn't ideal, because you get unused imports warnings from most code analysis tools, and invariably you'll have to deal with someone 'optimizing' those imports later, and breaking your conftest.

@nicoddemus
Copy link
Member

nicoddemus commented Jun 27, 2018

I see. Usually putting a few # noqa solves the problem, but I see your point.

Btw, you don't want to use pytest_plugins because you don't want to make the fixtures globally available?

I ask because pytest_plugins will also work for fixtures:

pytest_plugin = ['myapp.some_fixtures', 'myapp.other_fixtures']

@astraw38
Copy link
Author

Exactly. It's rather unintuitive that it would affect global scope. For most fixtures, not that big of a deal, but could be a problem with autouse fixtures (and would pollute the output of pytest --fixtures).

@nicoddemus
Copy link
Member

OK, thanks for the clarification.

@ikonst
Copy link
Contributor

ikonst commented Jul 5, 2018

@astraw38 see the approach I've eventually adopted:
#3582 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: fixtures anything involving fixtures directly or indirectly type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

4 participants