You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GitMate.io thinks possibly related issues are #2934 (capsysbinary fixture), #3377 (Rescope a fixture), #538 (Fixture scope documentation), #794 (fixture named "request" fails), and #484 (Order of class fixtures).
But I'm curious, what use cases do you have in mind?
One that I can think of is deprecating one fixture name over the another (for example), but even in that case I would still want to raise a deprecation warning on the deprecated fixture.
@ggens based on your examples its a much better pattern to just declare a factory fixture and use it from other fixtures like pytests own tmpdir factory for example
I looked tmpdir factory pattern by my requirement is different of this usage by these points:
scope function for fixture_factory
many call of this fixture for one test
... I don't see how tmpdir factory pattern answer of these points. My requirement is not maybe the good "pytest-way" (or pythonic) but ... one fixture must be only specific behavior ?
one thing is certain, you are not describing your actual use-case as long as you dont, there is nothing we can do to help you, im not going to participate in this as longer as its just a X-Y problem
@ggens that is a specific example if a implementation that is trimmed down so much that tis no longer a use-case, but rather a disconnected code example of no value
@ggens thanks for posting, but as @RonnyPfannschmidt said, your examples doesn't convey why the 1st example is much superior to the second, besides being just a little shorter (17 vs 13 lines).
Can you post real world scenarios where this would be useful? I can see it being used whenever someone has a factory and a fixed set of instantiations, but this seems like a rare use case.
@RonnyPfannschmidt@nicoddemus afterthought , I'm agree with you. It's too specific case which does not bring anything.
Well, I think new design for my case but should need class fixture
May you talk me about this ? is it planned ? just an idea? people work on this feature ? ( i'm really interested to participate)
thanks a lot again.
@RonnyPfannschmidt I'm not agree with you, example of @nicoddemus show an add value with the first case: Avoiding to encapsulate class in function for potentially an other usage (and it's join my issue in my current work)
@RonnyPfannschmidt I don't see much value either, but I think if this can be implemented cleanly and non-intrusively I wouldn't mind adding it (unless we can already foresee problems with the approach).
@nicoddemus i am very strictly opposed to burning class level fixtures as just a new way to spell functions when we could get real and actual interaction out of it ^^
Activity
pytestbot commentedon Jul 3, 2018
GitMate.io thinks possibly related issues are #2934 (capsysbinary fixture), #3377 (Rescope a fixture), #538 (Fixture scope documentation), #794 (fixture named "request" fails), and #484 (Order of class fixtures).
nicoddemus commentedon Jul 4, 2018
Hi @ggens, thanks for writing.
The current workaround for that is:
But I'm curious, what use cases do you have in mind?
One that I can think of is deprecating one fixture name over the another (for example), but even in that case I would still want to raise a deprecation warning on the deprecated fixture.
RonnyPfannschmidt commentedon Jul 4, 2018
the main issue that op didnt explain what he/she wants to actually do
without the use-case we have no idea whats actually meant
ggens commentedon Jul 4, 2018
@RonnyPfannschmidt , I would like collect request.fixturename to pass into class factory.
RonnyPfannschmidt commentedon Jul 4, 2018
@ggens based on your examples its a much better pattern to just declare a factory fixture and use it from other fixtures like pytests own tmpdir factory for example
ggens commentedon Jul 4, 2018
I looked tmpdir factory pattern by my requirement is different of this usage by these points:
... I don't see how tmpdir factory pattern answer of these points. My requirement is not maybe the good "pytest-way" (or pythonic) but ... one fixture must be only specific behavior ?
RonnyPfannschmidt commentedon Jul 4, 2018
one thing is certain, you are not describing your actual use-case as long as you dont, there is nothing we can do to help you, im not going to participate in this as longer as its just a X-Y problem
nicoddemus commentedon Jul 5, 2018
@ggens perhaps some example code demonstrating what you want to do (even if it does not work) would help?
ggens commentedon Jul 5, 2018
my actual case seems :
... and i would like just this
RonnyPfannschmidt commentedon Jul 5, 2018
@ggens that is a specific example if a implementation that is trimmed down so much that tis no longer a use-case, but rather a disconnected code example of no value
nicoddemus commentedon Jul 5, 2018
@ggens thanks for posting, but as @RonnyPfannschmidt said, your examples doesn't convey why the 1st example is much superior to the second, besides being just a little shorter (17 vs 13 lines).
Can you post real world scenarios where this would be useful? I can see it being used whenever someone has a factory and a fixed set of instantiations, but this seems like a rare use case.
ggens commentedon Jul 6, 2018
@RonnyPfannschmidt @nicoddemus afterthought , I'm agree with you. It's too specific case which does not bring anything.
Well, I think new design for my case but should need class fixture
May you talk me about this ? is it planned ? just an idea? people work on this feature ? ( i'm really interested to participate)
thanks a lot again.
RonnyPfannschmidt commentedon Jul 6, 2018
currently nobody is working on it, its not clear how to enable it yet
nicoddemus commentedon Jul 7, 2018
Thanks @ggens,
FWIW, this is how I imagine class fixtures would work:
Would be the equivalent of:
RonnyPfannschmidt commentedon Jul 7, 2018
If that was it they wouldnt add value, -1
ggens commentedon Jul 9, 2018
@RonnyPfannschmidt I'm not agree with you, example of @nicoddemus show an add value with the first case: Avoiding to encapsulate class in function for potentially an other usage (and it's join my issue in my current work)
nicoddemus commentedon Jul 10, 2018
@RonnyPfannschmidt I don't see much value either, but I think if this can be implemented cleanly and non-intrusively I wouldn't mind adding it (unless we can already foresee problems with the approach).
RonnyPfannschmidt commentedon Jul 10, 2018
@nicoddemus i am very strictly opposed to burning class level fixtures as just a new way to spell functions when we could get real and actual interaction out of it ^^
nicoddemus commentedon Jul 10, 2018
Oh that's a good point. I agree then that we should wait until a more compelling use case appears. 👍
sp-ricard-valverde commentedon Jul 28, 2020
Sorry to reopen this, but I might have actually found a use case for the multiple naming of a single fixture:
In this case
match_filesandunmatch_filescould easily be the same fixture with different appropriate names, but the alternate solution:Won't work as the
requestcontext is lost and cannot be passed fromunmatch_filestomatch_files.laike9m commentedon Dec 5, 2020
Would love to see this. Return from another fixture doesn't work if using
yield.The-Compiler commentedon Dec 5, 2020
yield from other_fixtureprobably would though, no?laike9m commentedon Dec 6, 2020
Which gives the error "Fixtures are not meant to be called directly"
I have not found a good way to reuse a fixture without defining a non-fixture function and call it in both fixtures.