Skip to content

parametrized fixture with session scope initialized twise #684

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
pytestbot opened this issue Feb 18, 2015 · 3 comments
Closed

parametrized fixture with session scope initialized twise #684

pytestbot opened this issue Feb 18, 2015 · 3 comments
Labels
topic: parametrize related to @pytest.mark.parametrize type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

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.


@pytestbot
Copy link
Contributor Author

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

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
@pfctdayelise
Copy link
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

@nicoddemus
Copy link
Member

Fixed in #1766

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: parametrize related to @pytest.mark.parametrize type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

3 participants