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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:56:02+00:00 2026-06-01T21:56:02+00:00

I am new to py.test and I am using funargs to generate some test

  • 0

I am new to py.test and I am using funargs to generate some test data before the tests get executed. I want to have pytest_generate hook use the funcargs value and pass it to the test function. For e.g. I have a function “do_something” which queries a database for a given set of arguments and sets user’s enviroment accordingly. Considering that we have a multi site setup, I want to ensure that the database has the entries against which the test is performed, before the test gets executed.

def pytest_funcarg__data(request):
    # Ensure test data exist in the data base
    # Perform all the checks
    # Final values
    values = [['option1', 'option2', 'option3'],
              ['option1', 'option2'],
              ['option2', 'option3']]
    # Expected result 
    results = [['output1'],
               ['output2'],
               ['output3']]

    return (values, results)

def test_do_something(value, result):       
    assert do_something(value) == result

Ideally. I want to iterate though the values and pass them to my test function. How can I do that?

Currently I am doing this:

def pytest_funcarg__data(request):
    #same as above

def pytest_funcarg__pass_data(request):
    data = request.getfuncargvalue("data")
    return (data[0][request.param],
                data[1][request.param])

def pytest_generate_tests(metafunc):
    if 'pass_data' in metafunc.funcargnames:
        # If number of test cases change the change needs to made here too
        metafunc.parametrize("pass_data", [0, 1, 2], indirect=True)

def test_do_something(pass_data):
    assert do_something(pass_data[0] == pass_data[1]

Now, this works. But everytime I add a test case, I need to update the generate_test hook. I am thinking there might be a simpler way to do this ?

  • 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-01T21:56:05+00:00Added an answer on June 1, 2026 at 9:56 pm

    the pytest_generate_tests hook is executed when tests are collected. The pytest_funcarg__data factory is called when the test is executed. Test execution happens after test collection so there is no way you could call something like “getfuncargvalue” during collection.

    However, it’s not clear from your example why you want to use both – here is a generate_tests that should work directly with your example test:

    def pytest_generate_tests(metafunc):
        params = [("input", "output")]
        metafunc.parametrize(("test_case", "result"), params)
    

    HTH. holger

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

Sidebar

Related Questions

I'm writing a JUnit test using JUnitPerf. Here, I want to generate some entries
I have a simple controller test using MvcContrib's test helpers: var controller = new
I have a set of Happstack.State MACID methods that I want to test using
Is it a good idea to start new test framework using Selenium web driver
I am using VS2010 to create a new unit test project to test my
Im trying to test my successfully creates a new user after login (using authlogic).
I've been using ShowDialog() in following way for all my new Windows. SomeGui test
I am trying to test a web page using Selenium IDE. Am new to
public Form1() { InitializeComponent(); Collection<Test> tests = new Collection<Test>(); tests.Add(new Test(test1)); tests.Add(new Test(test2)); foreach
I have the following test using NMock which fails. It used to work when

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.