Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pytest not picking up configurations inside pytest.ini

I am trying to use values that I have in pytest.ini during testing but keep getting an error FAILED tests/test_post_train.py::test_config - ValueError: unknown configuration value: 'rmse'. I am using the method outline in this similar question.

pytest.ini:

[pytest]
rmse = 40_000
inference_time = 0.5

tests/test_post_train.py:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

def pytest_addoption(parser):
    parser.addini("rmse", "Min RMSE score for a model to past post-train test")
    parser.addini(
        "inference_time", "Max inference time for the model to be making predictions"
    )


def test_config(request):
    score = request.config.getini("rmse")
    assert score == 40_000

>Solution :

pytest_addoption is a hook, so it should be in conftest.py and not in the test file

conftest.py:

def pytest_addoption(parser):
    parser.addini("rmse", "Min RMSE score for a model to past post-train test")
    parser.addini(
        "inference_time", "Max inference time for the model to be making predictions"
    )

test_post_train.py:

def test_config(request):
    score = request.config.getini("rmse")
    assert int(score) == 40_000
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading