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

Documentation on plugins should explain why importing them is bad #7754

Closed
mgrazebrook opened this issue Sep 14, 2020 · 1 comment · Fixed by #7772
Closed

Documentation on plugins should explain why importing them is bad #7754

mgrazebrook opened this issue Sep 14, 2020 · 1 comment · Fixed by #7772
Labels
topic: fixtures anything involving fixtures directly or indirectly type: docs documentation improvement, missing or needing clarification type: question general question, might be closed after 2 weeks of inactivity

Comments

@mgrazebrook
Copy link

mgrazebrook commented Sep 14, 2020

Intuitively, I re-used a fixture not by making it a plugin but by importing it from a library I created which is shared by several projects. This creates flake8 error F811 and caused me to read up why this should not be OK. This was not a quick journey and didn't lead to clear answers.

The problem I'm solving: I have a test library which contains a fixture for setting up database test data. It's shared by several projects: this means it can't be defined in a project's conftest.py (other than by copy-paste). The fixture is used to create project-specific fixtures.

This is the same case as nicely documented here:

https://mail.python.org/pipermail/code-quality/2017-May/000901.html

or here:

https://stackoverflow.com/questions/43746413/how-do-i-get-flake8-to-work-with-f811-errors

Importing fixtures like this works. I haven't yet encountered any disadvantage. However after a bit of googling, reading and asking I found that this is not how one's supposed to do this but no explanation of why.

I'd like an update to the documentation here:

https://docs.pytest.org/en/latest/writing_plugins.html

It would be good if search terms such as "reuse pytest fixtures between projects or from a library" took me here.

It would be good if the documentation explained why re-using fixtures by importing from a pip installed library is a bad thing and if it really is a bad thing, perhaps the code should give some sort of warning if they're used that way.

It would be nice if the help text gave a direct answer to 'how do I write a pluging fixture' rather than having to trawl through the linked examples.

@Zac-HD Zac-HD added topic: fixtures anything involving fixtures directly or indirectly type: docs documentation improvement, missing or needing clarification type: question general question, might be closed after 2 weeks of inactivity labels Sep 15, 2020
nicoddemus added a commit to nicoddemus/pytest that referenced this issue Sep 19, 2020
@nicoddemus
Copy link
Member

Thanks @mgrazebrook for the feedback!

You are completely correct, an explicit section about that topic is missing from our docs. I've opened #7772 that adds that into fixture.html, in a format which I believe fits with the rest of the document. Please take a look and feel free to post any comments in the PR. 👍

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: docs documentation improvement, missing or needing clarification type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants