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 8879173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:53:36+00:00 2026-06-14T19:53:36+00:00

In pytest, I can pass parameters to test (using fixtures or the decorator @pytest.fixture(params=list-of-params)

  • 0

In pytest, I can pass parameters to test (using fixtures or the decorator @pytest.fixture(params=list-of-params)).

When the tests are done, if a test fails, the parameter that was passed is shown on the results, as in TestCheckoutPage.test_address_edit[True] or False if it was false.

How can I access those parameters and add them to a finalizer? request.param doesn’t seem to work, even though that is how you would get the parameter when making a fixture:

@pytest.fixture(params=[True, False])
def user(request):
    return request.param

That works. But if I try to pass it to a test:

class TestClass:
    def test_something(self, user):
        pass

And then, using an autouse fixture to collect info on it:

@pytest.fixture(autouse=True)
def set_driver(self, request):
    print request.param

That throws an error, saying there is no param in FixtureRequest.

Is there a way that I can get that parameter back? I’m trying to have Selenium take a screenshot when tests fail, but because tests with parameters have the same name and classname and all, it is writing a file for the first execution, and then overwriting it the second, third, …, time around. So I would like to add the parameter to the file name to avoid this.

Thanks!

  • 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-14T19:53:37+00:00Added an answer on June 14, 2026 at 7:53 pm

    Indeed,request.param is only available in the fixture function where the parametrization is defined. If you need user in the set_driver fixture you can try this:

    import pytest
    
    @pytest.fixture(params=[True, False])
    def user(request):
        return request.param
    
    class TestHello:
        @pytest.fixture(autouse=True)
        def set_driver(self, user):
            print "set_driver sees", user
    
        def test_method(self):
            assert 0
    

    If you only want to have set_driver do something if user is actually involved in the test, then you could do something like this:

    import pytest
    
    @pytest.fixture(params=[True, False], scope="module")
    def user(request):
        return request.param
    
    @pytest.fixture(autouse=True)
    def set_driver(request):
        if "user" in request.fixturenames:
            user = request.getfuncargvalue("user")
            print "set_driver sees", user
    
    
    def test_function(user):
        assert 0
    
    def test_function_nouser():
        assert 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With pytest, one can mark tests using a decorator @pytest.mark.slow def some_slow_test(): pass Then,
When running py.test using a plugin that loads xmlrpclib the test run fails with:
I am using py.test to write some tests and in my tests I utilize
Using py.test, two tests called the same in different directory causes py.test to fail.
Using the shell, I can do this: >>> from django.test.client import Client >>> from
If I run the following command: >python manage.py test Django looks at tests.py in
The Django 1.4 documentation on tests states: For a given Django application, the test
I know this sounds strange but I can't get it. Here (http://pytest.org/dev/getting-started.html) it says
We use py.test in a project and use fixtures for most test cases. But
I'm evaluating test frameworks for automated system tests; so far I'm looking for a

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.