Skip to content

Access the CLI parameters when running with pytest xdist #358

@david-fliguer-ws

Description

@david-fliguer-ws

Hi, I have the following script called test_cli.py

import sys
def test_one():
    print(sys.argv[1])
def test_two():
    print(sys.argv[1])

When I run it like this

pytest -s

I can see the output -s (Which is fine because it is the second parameter of the CLI) but when I run it with pytest xdist as

pytest -s -n auto

I get the following output

================================== FAILURES ===================================
__________________________________ test_one ___________________________________
[gw0] win32 -- Python 3.6.4 c:\python36-32\python.exe

    def test_one():
>       print(sys.argv[1])
E       IndexError: list index out of range

test_cli.py:3: IndexError
__________________________________ test_two ___________________________________
[gw1] win32 -- Python 3.6.4 c:\python36-32\python.exe

    def test_two():
>       print(sys.argv[1])
E       IndexError: list index out of range

test_cli.py:5: IndexError
========================== 2 failed in 3.49 seconds ===========================

How can I access the CLI parameters when running with pytest-xdist ?
I need to use one of the parameters of the CLI to control the behaviour of one of my fixtures that is shared between tests and processes..

Thanks,

David

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions