Parametrizing dependent fixtures
Hello pytest team! Recently I've came across a talk about pytest by Gabe Hollombe https://youtu.be/RcN26hznmk4 One thing that he mentioned really caught my eye. Close to the end of the talk he speaks about parametrizing dependent fixtures by using @pytest.mark.parametrize. Here is link to that moment: https://youtu.be/RcN26hznmk4?t=2397 This looks like a very helpful feature. I tired it out on my own and yes it works: https://gist.github.com/Kanguros/e455901f5b940098d1d18628a27cbdb2 Unfortunately I could not find anything about this in the docs. Or maybe I'm just reading them in the wrong way. Anyway I would like to confirm that this is valid way of using the parametrize marker. Does this have any drawbacks? Is it reliable? Up till now I've only been aware of parametrizing fixtures using @pytest.fixture(params=...) Keep up the great work and thank you. Edgar
Hi Edgar, On Mon, Jan 8, 2018 at 10:32 AM Edgar Ostrowski <edgar.ostrowski@gmail.com> wrote:
Anyway I would like to confirm that this is valid way of using the parametrize marker.
I did not look at the video yet, but fixture parametrization only works by using @pytest.fixture(params=...). Markers don't do anything when applying to fixtures. Hope that clarifies things! Cheers, Bruno.
Hi, my understanding is, that the direct parametrization replaces the fixture lookup for the involved tests, which is not a planned "feature" per se, but still a neat tool to have -- Ronny 2018-01-08 14:07 GMT+01:00 Bruno Oliveira <nicoddemus@gmail.com>:
Hi Edgar,
On Mon, Jan 8, 2018 at 10:32 AM Edgar Ostrowski <edgar.ostrowski@gmail.com> wrote:
Anyway I would like to confirm that this is valid way of using the parametrize marker.
I did not look at the video yet, but fixture parametrization only works by using @pytest.fixture(params=...). Markers don't do anything when applying to fixtures.
Hope that clarifies things!
Cheers, Bruno.
_______________________________________________ pytest-dev mailing list pytest-dev@python.org https://mail.python.org/mailman/listinfo/pytest-dev
-- Red Hat GmbH, http://www.de.redhat.com/, Registered seat: Grasbrunn, Commercial register: Amtsgericht Muenchen, HRB 153243, Managing Directors: Charles Cachera, Michael Cunningham, Michael O'Neill, Eric Shander
A disadvantage could be that the fixture code (of the depended fixture) will not be executed. This means no preparation and cleanup steps are executed. From: pytest-dev [mailto:pytest-dev-bounces+davin.geiger=intel.com@python.org] On Behalf Of Ronny Pfannschmidt Sent: Monday, January 8, 2018 14:36 To: Bruno Oliveira <nicoddemus@gmail.com> Cc: Edgar Ostrowski <edgar.ostrowski@gmail.com>; pytest-dev <pytest-dev@python.org> Subject: Re: [pytest-dev] Parametrizing dependent fixtures Hi, my understanding is, that the direct parametrization replaces the fixture lookup for the involved tests, which is not a planned "feature" per se, but still a neat tool to have -- Ronny 2018-01-08 14:07 GMT+01:00 Bruno Oliveira <nicoddemus@gmail.com<mailto:nicoddemus@gmail.com>>: Hi Edgar, On Mon, Jan 8, 2018 at 10:32 AM Edgar Ostrowski <edgar.ostrowski@gmail.com<mailto:edgar.ostrowski@gmail.com>> wrote: Anyway I would like to confirm that this is valid way of using the parametrize marker. I did not look at the video yet, but fixture parametrization only works by using @pytest.fixture(params=...). Markers don't do anything when applying to fixtures. Hope that clarifies things! Cheers, Bruno. _______________________________________________ pytest-dev mailing list pytest-dev@python.org<mailto:pytest-dev@python.org> https://mail.python.org/mailman/listinfo/pytest-dev -- Red Hat GmbH, http://www.de.redhat.com/, Registered seat: Grasbrunn, Commercial register: Amtsgericht Muenchen, HRB 153243, Managing Directors: Charles Cachera, Michael Cunningham, Michael O'Neill, Eric Shander Intel Deutschland GmbH Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Christian Lamprechter Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928
Curious. I'm rather reluctant to tell people to use or rely on this however. Which I guess is the actual question that was asked. ;-) To me this seems like an implementation detail of the mark.parametrize decorator. Besides, is it really a good idea to make your parametrisation so indirect? I think you're breaking the abstraction fixtures are trying to create for you: You request the fixture and you should not be caring about how to create it, about whether is uses other fixtures to create itself and whether or not it is parametrised. I know there are exceptions to all rules, but it's a good design consideration to think about before constructing many intricately and tightly coupled dependencies. Regards, Floris "Geiger, Davin" <davin.geiger@intel.com> writes:
A disadvantage could be that the fixture code (of the depended fixture) will not be executed.
This means no preparation and cleanup steps are executed.
From: pytest-dev [mailto:pytest-dev-bounces+davin.geiger=intel.com@python.org] On Behalf Of Ronny Pfannschmidt Sent: Monday, January 8, 2018 14:36 To: Bruno Oliveira <nicoddemus@gmail.com> Cc: Edgar Ostrowski <edgar.ostrowski@gmail.com>; pytest-dev <pytest-dev@python.org> Subject: Re: [pytest-dev] Parametrizing dependent fixtures
Hi,
my understanding is, that the direct parametrization replaces the fixture lookup for the involved tests, which is not a planned "feature" per se, but still a neat tool to have
-- Ronny
2018-01-08 14:07 GMT+01:00 Bruno Oliveira <nicoddemus@gmail.com<mailto:nicoddemus@gmail.com>>: Hi Edgar,
On Mon, Jan 8, 2018 at 10:32 AM Edgar Ostrowski <edgar.ostrowski@gmail.com<mailto:edgar.ostrowski@gmail.com>> wrote: Anyway I would like to confirm that this is valid way of using the parametrize marker.
I did not look at the video yet, but fixture parametrization only works by using @pytest.fixture(params=...). Markers don't do anything when applying to fixtures.
Hope that clarifies things!
Cheers, Bruno.
_______________________________________________ pytest-dev mailing list pytest-dev@python.org<mailto:pytest-dev@python.org> https://mail.python.org/mailman/listinfo/pytest-dev
--
Red Hat GmbH, http://www.de.redhat.com/, Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Michael Cunningham, Michael O'Neill, Eric Shander Intel Deutschland GmbH Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Christian Lamprechter Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928 _______________________________________________ pytest-dev mailing list pytest-dev@python.org https://mail.python.org/mailman/listinfo/pytest-dev
Thank you guys for answering my question. Everything is clear now. I was thinking that maybe this was missing from the documentation. But it makes no sens add it since it not a real feature. Let's just hope that people don't using it too extensively. Thank you, keep up the good work. Edgar 2018-01-08 21:32 GMT+01:00 Floris Bruynooghe <flub@devork.be>:
Curious. I'm rather reluctant to tell people to use or rely on this however. Which I guess is the actual question that was asked. ;-) To me this seems like an implementation detail of the mark.parametrize decorator.
Besides, is it really a good idea to make your parametrisation so indirect? I think you're breaking the abstraction fixtures are trying to create for you: You request the fixture and you should not be caring about how to create it, about whether is uses other fixtures to create itself and whether or not it is parametrised. I know there are exceptions to all rules, but it's a good design consideration to think about before constructing many intricately and tightly coupled dependencies.
Regards, Floris
"Geiger, Davin" <davin.geiger@intel.com> writes:
A disadvantage could be that the fixture code (of the depended fixture) will not be executed.
This means no preparation and cleanup steps are executed.
From: pytest-dev [mailto:pytest-dev-bounces+davin.geiger= intel.com@python.org] On Behalf Of Ronny Pfannschmidt Sent: Monday, January 8, 2018 14:36 To: Bruno Oliveira <nicoddemus@gmail.com> Cc: Edgar Ostrowski <edgar.ostrowski@gmail.com>; pytest-dev < pytest-dev@python.org> Subject: Re: [pytest-dev] Parametrizing dependent fixtures
Hi,
my understanding is, that the direct parametrization replaces the fixture lookup for the involved tests, which is not a planned "feature" per se, but still a neat tool to have
-- Ronny
2018-01-08 14:07 GMT+01:00 Bruno Oliveira <nicoddemus@gmail.com<mailto:n icoddemus@gmail.com>>: Hi Edgar,
On Mon, Jan 8, 2018 at 10:32 AM Edgar Ostrowski < edgar.ostrowski@gmail.com<mailto:edgar.ostrowski@gmail.com>> wrote: Anyway I would like to confirm that this is valid way of using the parametrize marker.
I did not look at the video yet, but fixture parametrization only works by using @pytest.fixture(params=...). Markers don't do anything when applying to fixtures.
Hope that clarifies things!
Cheers, Bruno.
_______________________________________________ pytest-dev mailing list pytest-dev@python.org<mailto:pytest-dev@python.org> https://mail.python.org/mailman/listinfo/pytest-dev
--
Red Hat GmbH, http://www.de.redhat.com/, Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Michael Cunningham, Michael O'Neill, Eric Shander Intel Deutschland GmbH Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Christian Lamprechter Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928 _______________________________________________ pytest-dev mailing list pytest-dev@python.org https://mail.python.org/mailman/listinfo/pytest-dev
participants (5)
-
Bruno Oliveira -
Edgar Ostrowski -
Floris Bruynooghe -
Geiger, Davin -
Ronny Pfannschmidt