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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:46:41+00:00 2026-06-07T02:46:41+00:00

I include at conftetst.py my own command line options def pytest_addoption(parser): parser.addoption(–backend , default=test_backend,

  • 0

I include at conftetst.py my own command line options

def pytest_addoption(parser):
    parser.addoption("--backend" , default="test_backend",
        help="run testx for the given backend, default: test_backend")

and

def pytest_generate_tests(metafunc):
    if 'backend' in metafunc.funcargnames:
       if metafunc.config.option.backend:
          backend = metafunc.config.option.backend
          backend = backend.split(',')
          backend = map(lambda x: string.lower(x), backend)
        metafunc.parametrize("backend", backend)

If I use this command line option inside a normal function inside a module:

module: test_this.py;  

def test_me(backend): 
  print backend

it works as expected.

Now I want to include the setup_module function to create /copy some stuff before some tests:

def setup_module(backend):
   import shutil
   shutil.copy(backend, 'use_here')
   ...

unfortunately I have now idea how to get access to this command line option inside the setup_module function.
Nothing works, what I tried.

Thanks for help, suggestions.

Cheers

  • 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-07T02:46:44+00:00Added an answer on June 7, 2026 at 2:46 am

    There is a API-extension under discussion which would allow to use funcargs in setup resources and your use case is a good example for it. See here for the V2 draft under discussion: http://pytest.org/latest/resources.html

    Today, you can solve your problem like this::

    # contest of conftest.py
    
    import string
    
    def pytest_addoption(parser):
        parser.addoption("--backend" , default="test_backend",
            help="run testx for the given backend, default: test_backend")
    
    def pytest_generate_tests(metafunc):
        if 'backend' in metafunc.funcargnames:
            if metafunc.config.option.backend:
                backend = metafunc.config.option.backend
                backend = backend.split(',')
                backend = map(lambda x: string.lower(x), backend)
            metafunc.parametrize("backend", backend, indirect=True)
    
    def setupmodule(backend):
        print "copying for", backend
    
    def pytest_funcarg__backend(request):
        request.cached_setup(setup=lambda: setupmodule(request.param),
                             extrakey=request.param)
        return request.param
    

    Given a test module with two tests:

    def test_me(backend):
        print backend
    
    def test_me2(backend):
        print backend
    

    you can then run to check that things happen as you expect:

    $ py.test -q -s –backend=x,y

    collected 4 items
    copying for x
    x
    .copying for y
    y
    .x
    .y

    4 passed in 0.02 seconds

    As there are two backends under test you get four tests but the module-setup is only done once per each backend used in a module.

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

Sidebar

Related Questions

#include <iostream> #include <tuple> int main(){ auto bt=std::make_tuple(std::tuple<>(),std::tuple<std::tuple<>>()); //Line 1 auto bt2=std::make_tuple(std::tuple<>(),std::tuple<>()); //Line 2
#include <iostream> #include <fstream> using namespace std; int main() { ifstream stream1(source.txt); string line
#include<stdio.h> #include<stdlib.h> char* re() { char *p = hello; return p; } int main()
#include <iostream> using namespace std; int main() { int a, b, c, max; cout<<a=;
#include <iostream> #include <cassert> #include <vector> #include <ctime> #include <cstdlib> #include <Windows.h> using namespace
#include <iostream> #include <string.h> using namespace std; int main() { int e=0; int b=0;
#include <boost/smart_ptr.hpp> class Base { }; class Derived : public Base { public: Derived()
#include <list> using std::list; class foo { ... class bar : public foo {
#include <iostream> #include <string> using namespace std; string crash() { } int noCrash() {
#include <gtk/gtk.h> #include <gtksourceview/gtksourceview.h> static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data) { gtk_main_quit();

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.