Skip to content
Advertisement

Tag: pytest

Using SQLAlchemy 1.4 classical / imperative mapping style?

I am using the clean architecture & TDD development method in my Python project. Updating from SQLAlchemy 1.3 to SQLAlchemy 1.4 broke the ability to test against an in-memory Postgres DB, and I can’t find how to fix the problem. Following DDD principles, the project uses the new imperative mapping syntax which replace classical mapping declarations. Here is a minimal

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. There are two internal implementations for Path, PosixPath and WindowsPath, which

How to conditionally skip instantiation of fixture in pytest?

Problem: I have a fixture that takes about 5 minutes to instantiate. This fixture relies on a fixture from another package that I cannot touch. The time of the fixture can be drastically sped up depending on the state of a different (must faster instantiating) fixture. For example, this is the psuedo code of what I am looking to do:

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 part of the source

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 cases on the backend. Using these two layers of fixtures, I’d like to

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 with a pretty simple example: Activate a fresh pyenv virtualenv and install the latest pytest with pip install

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 certain requirements that is not possible. Is there a way I

Advertisement