What is the canonical way to isolate unit tests in Python with assertion-style tests?

I recently asked this question and realized that I'd also like to know if there's a way to achieve 'expectation' isolation with assertion-style tests. I've copy and pasted a simple example of what...

How to test an infinite while loop with pytest

I am currently writing a little lib that interacts with a bamboo build server. Testing is done using pytest. I got stuck at the following problem. I want to test a while loop that runs till some...

py.test conftest - Modify Fixture Parameter Based on sys.argv

I have a working pytest environment for Selenium testing. I use a parameterized fixture in conftest.py that allows me to test all the different browsers without having to rewrite the test. I'd...

Pytest fixture finalizer TypeError 'NoneType' object is not callable

I have a simple pytest fixture to ensure that the test data file is present (and deleted at the end of the test), but if gives me the error described in the title. @pytest.fixture def...

pytest with setup.py test

I use instructions, that described here For test I use this command: py.test --ignore=env But if I use python setup.py test pytest runs all test (+ in env). How to skip test in env...

calling pytest from inside python code

I am writing a Python script for collecting data from running tests under different conditions. At the moment, I am interested in adding support for Py.Test. The Py.Test documentation clearly...

Chromedriver closing after test

So my understanding is that calling driver.quit or close is the the proper way to close the driver and associated window. However when running my tests, it seems that even without calling...

Getting python3 to work in jenkins

I'm having trouble getting python3 to work in jenkins. Jenkins is currently running in a docker container and i'm using pipeline scripts to facilitate CI/CD This is my Jenkinsfile for a python...

"Apps aren't loaded yet" when trying to run pytest-django

Using the (partial) polls app from the Django tutorial as an example, I'm trying to get pytest-django to run. Using the command django-admin startproject mysite2, I've created a project directory...

Describing failing assert statements in imported functions with pytest

Pytest nicely prints the values of variables in failing assert statement (e.g. example here). However, this does not work for assert failures in imported functions, example.py def func(): b =...

How do I Pytest a project using PEP 420 namespace packages?

I am trying to use Pytest to test a largish (~100k LOC, 1k files) project and there are several other similar projects for which I'd like to do the same, eventually. This is not a standard Python...

How to fix python-selenium error "connection refused" when initializing a selenium webdriver?

I am running very complex python-selenium tests on non-public webpages. In most cases these tests run fine, but sometimes one of these tests fail during the initialization of the webdriver...

Pytest: How to make sure a certain fixture is called first

I have some data in a_file which I need to parametrize my fixture with. Therefore, I wrote a helper function which returns a_list filled with the data from the file. Now I can easily parametrize...

Failure on unit tests with pytest, tornado and aiopg, any query fail

I've a REST API running on Python 3.7 + Tornado 5, with postgresql as database, using aiopg with SQLAlchemy core (via the aiopg.sa binding). For the unit tests, I use py.test with...

Persistent data among tests with django and pytest

The idea behind this question is simple to understand but complex to solve: I need to share data among tests. I have a Django project and I use pytest-django and pytest-descibe for defining and...

Unable to patch logging.Logger.info called inside celery task

I want to test that a specific celery task call logger.info exactly once when the task is invoked with the delay() API. And I want to do the test by patching logger.info . I want to test as...

Pytest fails on importing pyhive

I am working on writing some data tests. Super simple nothing crazy. Here is what my current directory looks like. . ├── README.md ├── hive_tests │   ├── __pycache__ │  ...

PyDap and Xarray remote access to LP DAAC

I would like to use xarray/pydap for remote access of data on the LP DAAC OpeNDAP server. I have an earth data account (username and password - login page), and I have added the LP DAAC OpeNDAP...

pytest run tests inside a class with a constructor

I want to write a test suite for an API. my project tree looks like: project tree I need to have a 'client' file with classes where we initialize all the helper functions(e.g. the actual request...

Can't debug Django unit tests within Visual Studio Code

I want to be able to run and debug unit tests for a Django project from within Visual Studio Code. I am an experienced developer, but fairly new to both Django and Visual Studio Code. The crux of...

How to rename the test cases of html report generated by PyTest

Below is the HTML report generated by PyTest with Test case name as "test_demo.py::test_demo_framework[0]" instead of this method's name I want to display some actual tests name like "Verify...

pytest fixture finalization in the presence of errors

I have a test bench setup where I make heavy use of fixtures to provide resources and "items to test" to the tests I have defined. This is great, it allows my test functions to contain as little...

How to use Pytest to test functions that generate random samples?

Lets say I generate some input numpy array data using a np.random.normal() in my test_func.py script that is using pytest. Now I want to call the func.py function that I am testing. How am I able...

Is there a way to add custom CLI arguments to pytest using the same syntax as would be used with the argparse module?

TLDR: I want to extent pytest's cli and I know how that can be done using their own API, but I was just wondering if there was a way to do so using the argparse module directly (or its syntax at...

how to create a custom python environment from yml file *with* downloads of missing packages

I am trying to build a python 3.5 environment that supports an old hddm library. Standard approaches fail due to my/anaconda's apparent inability in ignore (or downgrade) the 10.1 cuda library in...

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...

How do I get the JSON formof a Durable Rule in Python?

Our Python application currently loads Durable rules from a YAML file (which will soon be a database or Redis cache), then converts that YAML to JSON, before sending the JSON object to the Durable...

Type hints for pytests fixtures that return methods

Some of my pytest fixtures return a method. I would like to use type hints for all my methods. To say that a method return a method I can use Callable here. The problem here: I'm loosing the...

Pytest + Appium test framework

I'm very new to automation development, and currently starting to write an appium+pytest based Android app testing framework. I managed to run tests on a connected device using this code, that...

VSCode does not detect any of my pytest tests

I am trying to get my unit tests to show up in VSCode's test explorer, but it does not seem to be working. The test discovery does not fail with any errors in the output, but also does not show...