Skip to content

Tag: pytest

Unable to mock os name with Python on Windows

I have the following method: I’m trying to test it like this: But then the following error is raised: What is happening exactly? Answer What is happening here is that pytest internally uses a pathlib.Path object, which upon initialization asks for os.name to define which Path implementation to use. Ther…

Exclude some tests by default

I wish to configure pytest such that it excludes some tests by default; but it should be easy to include them again with some command line option. I only found -k, and I have the impression that that allows complex specifications, but am not sure how to go about my specific need… The exclusion should be…

Pytest: Nested use of request fixture

I’d like to get some help on how to run pytests with multiple layers of parameterized pytest fixtures. I have a global request-based fixture for selecting a base implementation of the system I’d like to test: I’d like to now run some additionally-parametrized tests against different test cas…

pytest breaks with pip install

I’m working in a repo that has tests and some test helper libraries in a directory named test (https://github.com/covid-projections/covid-data-model/tree/main/test). Mysteriously pip install dash seems to break our tests. I’m using python 3.7.9 in pyenv on a debian laptop. I reproduced the problem…

Import conftest.py from peer package

Currently, I have two packages as part of my test repository with the following folder structure: As part of this, my requirement is to call fixtures defined in Package_A/conftest.py from Package_B/test_B.py. I understand that this could be done easily if Package B was within Package A. However, because of ce…