Skip to content

Support @pytest.mark.usefixture in fixtures #5783

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

Closed
wants to merge 2 commits into from
Closed

Support @pytest.mark.usefixture in fixtures #5783

wants to merge 2 commits into from

Conversation

youtux
Copy link

@youtux youtux commented Aug 24, 2019

  • Target the master branch for bug fixes, documentation updates and trivial changes.
  • Target the features branch for new features, improvements, and removals/deprecations.
  • Include documentation when adding new features.
  • Include new tests or update existing tests when applicable.
  • Create a new changelog file in the changelog folder, with a name like <ISSUE NUMBER>.<TYPE>.rst. See changelog/README.rst for details.
  • Add yourself to AUTHORS in alphabetical order;

Followup from #3664 (comment).
I am trying to get the @pytest.mark.usefixture marker to work with fixtures as well.

@youtux youtux changed the base branch from master to features August 24, 2019 16:37
@bluetech

This comment has been minimized.

@nicoddemus
Copy link
Member

nicoddemus commented Feb 14, 2020

(Revisiting this)

The PR looks well written for a first draft, thanks! (Sorry for not commenting on it previously, missed the notification most likely).


I think once people notice that they can use @pytest.mark.usefixtures, they will probably also expect @pytest.mark.skipif to work too.

Is it a good idea to eventually support @pytest.mark.skipif (and the others) in fixtures? Perhaps the semantics should be "marks applied to fixtures mean that the marks are applied automatically to tests which use that fixture"? This would gain us all marks as part of fixtures. At first sight seems like a good idea, but I'm not sure.

@RonnyPfannschmidt what do you think?

Btw this discussion is out of scope for this PR, just me thinking aloud to get feedback.

@nicoddemus
Copy link
Member

Hmmm just realized that this technically might be a challenge, because marks usually are applied during collection, and fixtures are lazily evaluated during test call...

@RonnyPfannschmidt
Copy link
Member

its technically incredibly hard to correctly transfer markers from fixtures to nodes,
making one mark magically special is not going to be good in any way,

until we have a sound solution for markers on fixtures, its not acceptable to have some of them a little bit magically

a sound solution is hard to impossible right now as the fixture system has various features that make this more tricky (like replacing vs enhancing fixtures, dynamic fixture requests and a few more details) as well as the fact that the current internals of fixtures are rather frickly and fragile as the result of their development history

revisiting the original issue i have to note that while we improved some parts of marks, the parts that make it fundamentally a bad choice to support them on fixtures is still the same

@bluetech bluetech changed the base branch from features to master February 16, 2020 15:16
@bluetech
Copy link
Member

We've recently stopped using the features branch

(I've changed the base on my own now).

@nicoddemus
Copy link
Member

revisiting the original issue i have to note that while we improved some parts of marks, the parts that make it fundamentally a bad choice to support them on fixtures is still the same

Agree completely. 👍

@youtux
Copy link
Author

youtux commented Mar 1, 2020

I soon realized after digging a little bit into pytest internals that indeed this would require a major architectural change, not just a small patch.
Closing this PR as I am not continuing this development.

@youtux youtux closed this Mar 1, 2020
@nicoddemus
Copy link
Member

Thanks @youtux for trying! We appreciate it.

@jamt9000
Copy link

I think once people notice that they can use @pytest.mark.usefixtures, they will probably also expect @pytest.mark.skipif to work too.

Does the mechanism to use fixtures need to be a mark? How about defining @pytest.usefixtures that works for both fixtures and tests.

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.

5 participants