Test case execution order in pytest

I am using pytest. I have two files in a directory. In one of the files there is a long running test case that generates some output. In the other file there is a test case that reads that output....

In which order are pytest fixtures executed?

For an application I'm testing I'd like to create an autouse=True fixture which monkeypatches smtplib.SMTP.connect to fail tests if they try to send an email unexpectedly. However, in cases where...

how to write integration tests using pytest and how to repeat the integration tests

I am new to this so please do not mind if the question is not specific enough. I want to know how to club unit tests into a single integration test in pytest. Furthermore, I would like to repeat...

pytest fixtures in a separate directory

I'm looking to create a pytest structure where I can separate the fixtures from the tests completely. The reason for this separation is that I want to include the fixtures directory as an external...

pytest ordered plugin doesn't work with combination of multiple files

Hi I am using "http://pytest-ordering.readthedocs.org/en/develop/" and order works fine when I use decorators as below, import pytest @pytest.mark.run(order=3) def test_three(): assert...

Combine pytest html report into one single report

I use xunitmerge to merge all pytest junit xml output into one single junit xml. Command used to run pytest and merge are below: for i in `ls test_*` do test_suit=$(echo $i |cut -d'.'...

Override a pytest parameterized functions name

My parameters determine the name of my parameterized pytest. I will be using a some randomized params for these tests. In order for my reporting names in junit to not get messed up, I'd like to...

pytest - getting the value of fixture parameter

Is there a way to save the value of parameter, provided by pytest fixture: Here is an example of conftest.py # content of conftest.py import pytest def...

Django test VS pytest

I am new to django `unittest` and `pytest`. However, I started to feel that `pytest` test case is more compact and clearer. Here is my test cases: class OrderEndpointTest(TestCase): def...

How can I tell pytest-dependency to temporarily ignore test dependencies?

I've got a functional test suite using pytest-dependency to skip tests when other tests they depend on fail. That way, for example, if the login page is broken, I get one test failure saying "The...

How can you test that two dictionaries are equal with pytest in python

Trying to assert that two dictionaries that have nested contents are equal to each other (order doesn't matter) with pytest. What's the pythonic way to do this?

Pytest "run-around-tests" fixture to run only once before all tests in a class

I am testing the User message function of a web solution using pytest + selenium. The tests will generate a test message to a test user, and then log in that user to verify that the message indeed...

Disable pytest fixtures

Is it possible to disable fixtures in pytest? The reason I want to do that is that I'm using my own fixtures framework, currently like this (the pros and cons of different fixtures mechanisms...

What is the correct order for actual and expected in pytest?

This question gives the order assertEqual(expected, actual), albeit for the unittest package. But Pycharm, with pytest, prints out "Expected:..." and "Actual..." based on the order...

Pytest - test case execution order

I have some scripts with the tests for them and I need to run these tests in execution order explicitly defined by me. It looks like: # one.py import some lib class Foo(): def makesmth(self) ...

pytest - default fixture parameter value

I wrote a fixture in pytest which was not parametrized but is used by a lot of tests. Later I needed to parametrize this fixture. In order to not to have to mark.parametrize all the old tests I...

pytest fixtures and threads synchronizations

I'm trying to use pytest-xdist in order to make my tests run parallel, The issue is that each thread is going to the fixture that shared to all tests and executing it according to threads...

Unable to Instantiate Python Dataclass (Frozen) inside a Pytest function that uses Fixtures

I'm following along with Architecture Patterns in Python by Harry Percival and Bob Gregory. Around chapter three (3) they introduce testing the ORM of SQLAlchemy. A new test that requires a...

requests_mock NoMockAddress Exception

I'm currently trying to do unit tests using the requests_mock library in order to patch requests. I've written the following code: def test_general_search(requests_mock): params = {'query':...

Pytest schedule intervals between groups of tests

Is there any way of telling pytest to run a certain set of tests, then wait for a known amount of time, then run another set of tests? For example, if I have tests with the following...

pytest-asyncio with singletons causes conflicting event loops

I'm using dbus for IPC. In order to have exactly one bus throughout the livetime of my program I'm using a singleton here. For the sake of demonstration I'm connecting to NetworkManager but that...

pytest with workers ( -n 1 for example ) using xdist when test contains also multiprocessing

I'm using Python 3.6 Pytest 6.1.1 Pytest xdist 2.1.0 Pycharm 2018.3.7 Using HTML plugin for report as well with customization for the report I'm running automation test via pycharm >pytest with...

Pytest capture stdout of a certain test

Is there a way get the Captured stdout call just for a specific test without failing the test? So lets say I have 10 tests, plus a test_summary. test_summary really just prints some kind of...

How do you parametrize a pytest class with Hypothesis @given?

In order to test how my database behaves when I add two very similar data rows, I need to setup a new database for each combination of parameters. I'm also using Hypothesis' strategies to generate...

Need order and action of pytest hooks execution

Can anyone clarify how pytest hooks executes and what it does in each step? Mainly, could you please tell me why pytest_plugin_registered is repeated under pytest_sessionstart?. I checked...

How to pytest a Flask Endpoint

I'm getting started with Flask and Pytest in order to implemente a rest service with unit test, but i'm having some troouble. I'll like to make a simple test for my simple endpoint but i keep...

Using poetry on different machines

I am working on a Python project and recently started using poetry. I was originally working on the project using macOS 11.0, but as I near completion, I wanted to test it on a Linux workstation....

Parametrizing multiple tests dynamically in Python

I'm attempting to use Pytest to write a dynamic test suite, where the test data is held in a separate file, e.g. a YAML file or a .csv. I want to run multiple tests, all of which are parameterised...

Create multiple similar PyTest fixtures

I have a series of pytest fixtures which are very similar to each other in nature. The fixtures are passed to tests which verify that certain CSS selectors work properly. The code within each...

Simple example of Pandas ExtensionArray

It seems to me that Pandas ExtensionArrays would be one of the cases where a simple example to get one started would really help. However, I have not found a simple enough example...