I have a project directory looks like following
Projects/
....this_project/
........this_project/
............__init__.py
............code.py
............tests/
................conftest.py
................test_1.py
................test_2.py
and I added a command line option (--PALLADIUM_CONFIG) by putting following code into conftest.py
def pytest_addoption(parser):
parser.addoption("--PALLADIUM_CONFIG", action="store")
@pytest.fixture
def PALLADIUM_CONFIG(request):
return request.config.getoption("--PALLADIUM_CONFIG")
And what strange is:
if I cd into
Projects/this_project/this_project
or
Projects/this_project/this_project/tests
and run
py.test --PALLADIUM_CONFIG=***
if runs well
but if I locate myself in for example
Projects/this_project
or
Projects
then pytest gives me error
py.test: error: unrecognized arguments: --PALLADIUM_CONFIG=***
Many pytest settings can be set in a configuration file, which by convention resides on the root of your repository or in your tests folder.
Users can customize some pytest behavior using a configuration file called pytest. ini . This file is usually placed at the root of the repository and contains a number of configuration values that are applied to all test runs for that project.
The simplest way to skip a test function is to mark it with the skip decorator which may be passed an optional reason : @pytest. mark.
Conftest is a utility to help you write tests against structured configuration data. For instance, you could write tests for your Kubernetes configurations, Tekton pipeline definitions, Terraform code, Serverless configs or any other structured data.
That's a limitation of pytest itself. Take a look at the docs:
Note that pytest does not find conftest.py files in deeper nested sub directories at tool startup. It is usually a good idea to keep your conftest.py file in the top level test or project root directory.
One solution is to create an external plugin, or move the option to a conftest
file nearer the root.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With