Skip to content

parametrized fixture with session scope initialized twise #684

Closed

Description

@pytestbot

Originally reported by: BitBucket: aokhotin, GitHub: aokhotin


I attached two files were bug reproduced.
steps:

#!bash

$ py.test --version
This is pytest version 2.6.4, imported from /home/username/venv/local/lib/python2.7/site-packages/pytest.pyc

so there no any plugins.

#!bash

 py.test -sv
============================= test session starts ==============================
platform linux2 -- Python 2.7.6 -- py-1.4.26 -- pytest-2.6.4 -- /home/username/venv/bin/python
collected 21 items 

test_solar.py::test_one PASSED
test_solar.py::test_three[pluto-1] sun '1'
"sun '1'" - "pluto"
PASSED
test_solar.py::test_four[pluto-1] PASSED
test_solar.py::test_three[pluto-2] sun '2'
"sun '2'" - "pluto"
PASSED
test_solar.py::test_four[pluto-2] PASSED
test_solar.py::test_three[neptun-2] "sun '2'" - "neptun"
PASSED
test_solar.py::test_four[neptun-2] PASSED
test_solar.py::test_three[neptun-1] sun '1'
"sun '1'" - "neptun"
PASSED
test_solar.py::test_four[neptun-1] PASSED
test_solar.py::test_three[neptun-3] sun '3'
"sun '3'" - "neptun"
PASSED
test_solar.py::test_four[neptun-3] PASSED
test_solar.py::test_three[pluto-3] "sun '3'" - "pluto"
PASSED
test_solar.py::test_four[pluto-3] PASSED
test_solar.py::test_three[neptun-4] sun '4'
"sun '4'" - "neptun"
PASSED
test_solar.py::test_four[neptun-4] PASSED
test_solar.py::test_three[pluto-4] "sun '4'" - "pluto"
PASSED
test_solar.py::test_four[pluto-4] PASSED
test_solar.py::test_three[neptun-5] sun '5'
"sun '5'" - "neptun"
PASSED
test_solar.py::test_four[neptun-5] PASSED
test_solar.py::test_three[pluto-5] "sun '5'" - "pluto"
PASSED
test_solar.py::test_four[pluto-5] PASSED

The fact that "sun '1'" have been initialized twise is unexpected.


Activity

  1. pytestbot commented on Feb 22, 2015

    @pytestbot
    ContributorAuthor

    Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt):


    i believe this is an artifact of fixture dependency ordering combined with test ordering
    while it is not "wrong", its certainly unfortunate, as it is bad for test time,

    also we could consider caching parametrized setupstate at session scope

  2. pfctdayelise commented on Jul 25, 2015

    @pfctdayelise
    Contributor

    test_solar.py

    __author__ = 'aokhotin'
    
    
    def test_one():
        pass
    
    
    def test_three(sunoption):
        pass
    
    
    def test_four(sunoption):
        pass
    

    conftest.py

    import pytest
    
    
    @pytest.fixture(scope="session", params=["1", "2", "3", "4", "5"])
    def sun(request):
        value = "sun '{}'".format(request.param)
        print value
        return value
    
    
    @pytest.fixture(scope="session", params=["pluto", "neptun"])
    def sunoption(sun, request):
        value = '"{}" - "{}"'.format(sun, request.param)
        print value
        return value
    
  3. nicoddemus commented on Jul 25, 2016

    @nicoddemus
    Member

    Fixed in #1766

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: parametrizerelated to @pytest.mark.parametrizetype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions