Giter VIP home page Giter VIP logo

Comments (3)

RonnyPfannschmidt avatar RonnyPfannschmidt commented on May 26, 2024

I believe there was a fix for this in the 8 series

We should warn better about implicit indirect parameters having different scopes

from pytest.

gjambaisivanandham avatar gjambaisivanandham commented on May 26, 2024

I believe there was a fix for this in the 8 series

We should warn better about implicit indirect parameters having different scopes

I just tried with the latest version 8.0.2 and the issue exists in it.

from pytest.

WarrenTheRabbit avatar WarrenTheRabbit commented on May 26, 2024

Thank you for posting, @gjambaisivanandham. I'm new to pytest as well so I am interested in exploring and understanding your issue.

These may be silly remarks coming from my ignorance of session scope but:

  • do your examples have syntax errors? It looks to me like response isn't defined in the body of your test functions, for example.
  • aren't you overriding the session fixture by directly parametrizing the test functions?
  • to not override your session fixture, shouldn't indirect=True be used?

Is this the fixture usage your are expecting from file.py below. Note that test_scenario_1 uses indirect=True in my example.

import pytest

@pytest.fixture(scope='session')
def my_fixture(request):
    """I am being used."""
    pass
    
@pytest.mark.parametrize('my_fixture', ['a','b'], indirect=True)
def test_scenario_1(my_fixture):
    pass

@pytest.mark.parametrize('my_fixture', ['a','b'])
def test_scenario_2(my_fixture):
    pass

Fixture usage:

$ pytest file.py --fixtures-per-test
-------------------------- fixtures used by test_scenario_1[a] ---------------------------
-------------------------------------- (file.py:10) --------------------------------------
my_fixture -- file.py:4
    I am being used.

-------------------------- fixtures used by test_scenario_1[b] ---------------------------
-------------------------------------- (file.py:10) --------------------------------------
my_fixture -- file.py:4
    I am being used.

-------------------------- fixtures used by test_scenario_2[a] ---------------------------
-------------------------------------- (file.py:14) --------------------------------------
my_fixture -- src/_pytest/python.py:1113
    no docstring available

-------------------------- fixtures used by test_scenario_2[b] ---------------------------
-------------------------------------- (file.py:14) --------------------------------------
my_fixture -- src/_pytest/python.py:1113
    no docstring available
  • @RonnyPfannschmidt: are you saying the parametrize mark should implicitly do parametrization of the session fixture here rather than creating a pseudo fixture for the argument my_fixture?

Thank you again, @gjambaisivanandham!

from pytest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.