Top "Pytest" questions

Simple powerful no-boilerplate testing with Python.

How can I limit the maximum running time for a unit test?

I am currently running some unit tests that might either take a long time before failing or run indefinitely. In …

python pytest
Mocking a imported function with pytest

I would like to test a email sending method I wrote. In file, format_email.py I import send_email. …

python mocking pytest magicmock
How to monkeypatch python's datetime.datetime.now with py.test?

I need to test functions which uses datetime.datetime.now(). What is the easiest way to do this?

python datetime mocking pytest
Pytest - error vs fail

Im migrating from PyUnit to Pytest, and I found, that Pytest, unlike PyUnit, does not distinguish fails and errors in …

python testing pytest python-unittest
Python project directory structure / pytest trouble

This should be the easiest problem on earth, but even after extensive searching and tinkering, I'm still in deep trouble …

python path pytest
How to skip a pytest using an external fixture?

Background I am running a py.test with a fixture in a conftest file. You can see the code below(…

python decorator pytest python-decorators
How to mock data as request.Response type in python

I would like to write some testcase to exercise object_check in isinstance(obj, requests.Response) logic. After I create …

python python-3.x pytest python-unittest python-unittest.mock
Any way to pass parameters into pytest fixture?

I am not talking about the Parameterizing a fixture feature that allows a fixture to be run multiple times for …

python pytest fixture
Is there a way to control how pytest-xdist runs tests in parallel?

I have the following directory layout: runner.py lib/ tests/ testsuite1/ testsuite1.py testsuite2/ testsuite2.py testsuite3/ testsuite3.py testsuite4/ …

python pytest xdist
Pytest monkeypatch isn't working on imported function

Suppose there are two packages in a project: some_package and another_package. # some_package/foo.py: def bar(): print(…

python unit-testing pytest