10000 Access cmd line arguments within from a test · Issue #2358 · pytest-dev/pytest · GitHub
[go: up one dir, main page]

Skip to content
Access cmd line arguments within from a test #2358
@inl-pd-autotest

Description

@inl-pd-autotest

Hi, how to access command line arguments within from a test_script.py?
suppose I do pytest --resolution 1280x1024 and my conftest.py is:

import pytest
def pytest_addoption(parser):
	parser.addoption('--resolution', metavar='resolution', default='1280x1024', help='specify resolution in format like that: "1280x720"')
def resolution(request):	# not sure this is needed for the example, but I need to access resolution in conftest.py's fixtures, so I have it.
	return request.config.getoption('--resolution')

and test_example.py is:

import pytest # to try 'pytestconfig.resolution'.
def test_example():
	print(resolution) # fails with NameError: name 'resolution' is not defined
	print(pytestconfig.resolution) # fails the same way. I don't know what pytestconfig really is, but docs say it is pytest config object with access to command line opts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0