Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9020155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:56:47+00:00 2026-06-16T04:56:47+00:00

I have two simple test setups and I’m trying to group them in one

  • 0

I have two simple test setups and I’m trying to group them in one fixture
and want the test function to pass in the ‘params’ to the fixture.

Here’s a contrived example, to explain my question.
Say I have the following pytest fixture:

@pytest.fixture(scope="module", params=['param1','param2'])
def myFixture(request):
    if request.param == 'param1':
        p = 5
    elif request.param == 'param2':
        p = 10
    return p

# would like to set request.param = ['param1'] for myFixture
def test_madeup(myFixture):
    assert myFixture == 5

# would like to set request.param = ['param2'] for myFixture
def test_madeup2(myFixture):
    assert myFixture == 10

Can I make it so that the params above are passed in as an input to the test_madeup function?
So, something like the following:

@pytest.fixture(scope="module", params=fixtureParams)
def myFixture(request):
    if request.param == 'param1':
        return 5
    elif request.param == 'param2':
        return 10


def test_madeup(myFixture, ['param1']):
    assert myFixture == 5

The above, of course, doesn’t work. The real case is a bit more complex,
but I just want to know if I can pass the params=['param1','param2']
to the fixture from the test_madeup function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:56:48+00:00Added an answer on June 16, 2026 at 4:56 am

    If i understand your question correctly, you basically want to select one instance of a parametrized fixture for executing with a test, by providing some info with the test. It’s not possible although we could probably think about a mechanism. I am not sure if the following solution maps to your whole problem, but here is one way to solve the above concrete case:

    import pytest
    
    @pytest.fixture(scope="module")
    def myFixture1():
        return 5
    
    @pytest.fixture(scope="module")
    def myFixture2():
        return 2
    
    @pytest.fixture(scope="module", params=["param1", "param2"])
    def myFixture(request):
        if request.param == 'param1':
            return request.getfuncargvalue("myFixture1")
        elif request.param == 'param2':
            return request.getfuncargvalue("myFixture2")
    
    def test_1(myFixture1):
        assert myFixture1 == 5
    
    def test_2(myFixture2):
        assert myFixture2 == 2
    
    def test_all(myFixture):
        assert myFixture in (2,5)
    

    This runs four tests, because the test_all is executed twice with both fixtures.

    If the setup of your fixtures is not heavy, you might also have one fixture that produces a list and an “iterating” parametrized one. A test could then grab the whole list and index it into it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I've faced weird issue. I have two simple queries where one of them
I am setting up a simple test page in Python. I only have two
I have made a simple test application for the issue, two winforms each containing
I have two relatively simple codes. One main activity and one intent service. Main
I have two functions that return simple strings. Both are registered. $.views.helpers({ parseDate: function
In Javascript, I have two versions of a recursive function, one that runs synchronously
I'm trying to learn PyInstaller. I created two simple files, Test.py: import os and
I have two functions in controller named step1 and step2. I want to pass
I have two simple submit buttons on my form, which work just fine: <button
Let's say I have two simple models project t.string :title vote t.references :project t.integer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.