How to properly assert that an exception gets raised in pytest?

Code: # coding=utf-8 import pytest def whatever(): return 9/0 def test_whatever(): try: whatever() except ZeroDivisionError as exc: pytest.fail(exc,...

django pytest - unable to create testdb

I have trouble creating a test DB and gives error as there is no database found. Im really not sure what is wrong and why database is not...

Python - InvocationError in tox running py.test and coverage test

My project has the following structure: my_project | setup.py tox.ini src | core_functions.py client.py server.py sql_database.py tests.py The tests.py file contains the...

How to set up entry_points in setup.cfg

I am moving my config from setup.py to setup.cfg and having issues setting up the entry_points parameter. At the moment I am using a hybrid approach which works, however, I would like to move the...

Pytest coverage with line coverage and minimum limits like karma/Istanbul

In Instanbul coverage module for Karma you can set thresholds for different kind of coverages. If some coverage doesnt meet its minimum then instanbul throws an error. This is very usefull when...

How to fix SSL Certificate Verification Error for a Gitlab CI build that uses docker in docker (dind) service for Python 3.x Architecture?

I am receiving SSL Certificate Verification Error from a gitlab CI build that uses docker in docker within a Python 3.x architecture. All CI build images are alpine linux based. I have setup a CI...

import file mismatch in pytest

I've got a file in the package with 'test' in its name and when I run pytest I got an error import file mismatch: imported module 'my_project.my_file_test' has this __file__ attribute: ...

Getting fixture not found in pytest

I am getting following error while running pytest using following code im unable to figure out whats wrong please find below code snippets. Console ouput...

Module not found running on command line

I have the following project structure: project/ example/ __init__.py foo.py boo.py meh.py tests/ example/ test_foo.py ...

Tox 0% coverage

I have a python project where I use: pipenv tox pytest and many more. Basically, I want to add tox to my gitlab pipelines. And almost everything seems to work, calling mypy, flake8 or black from...

How can I use pip cache in github actions?

I am having some issues with using cached pip in Github Actions. My workflow setup is name: tests on: [push, pull_request] jobs: linux: runs-on: ubuntu-18.04 strategy: ...

Is there a standard way to fail pytest if test coverage falls under x%

Right now the way I'm running things is I have a set of test cases written with pytest that I run, if they fail then I fix and rework on. If they pass I use pytest-cov to get coverage and manually...

Why is caplog.text empty, even though the function I'm testing is logging?

I'm trying to use pytest to test if my function is logging the expected text, such as addressed this question (the pyunit equivalent would be assertLogs). Following the pytest logging...

WARNING: Failed to generate report: No data to report error in python using pytest module

Sample.py code: def sum(num1, num2): return num1 + num2 def sum_only_positive(num1, num2): if num1 > 0 and num2 > 0: return num1 + num2 else: return...

How to append different pytest tests to the same junit xml file instead of overriding it?

I have the following function in a shell script: test_handler(){ FOLDER_NAME=$1 echo "running tests in: ${FOLDER_NAME} package" cd ${SOURCE_CODE_FOLDER}/${FOLDER_NAME} pipenv install...

Python project code coverage badge with coveralls / github actions

I'm trying to add a code coverage % badge to my repos README.md I'm currently using Github actions to automate my pytest testing. I had that working on its own, but ive been struggling trying to...

Pytest Not Deselecting Certain Tests (but should be in pytest.ini)

I've got a test suite set up and have been using pytest and pytest-django. To give some background: I am trying to do some integration testing with a headless browser and have pytest ignore...

setup.py/setup.cfg install all extras

I search for a possibility to 'inherit' other extras in the setup.cfg like so: [options.extras_require] all = <doc> <dev> <test> doc = sphinx dev = dvc twine # for...

Fatal Python Error when running pytest with QT

I'm new to pytest and I'm having trouble trying to run one of my test files. I'm getting the following output: ================================================== test session starts...

Why not getting 100% coverage on FastAPI with pytest-cov using starlettes TestClient

I simply do not understand the output from pytest-cov My test module is the following from starlette.testclient import TestClient def test_ping(test_app: TestClient): response =...

mognoengine and bson package not work together

I have one project which is depend on mongoengine and I am using one library which was using bson library. It structure like below. bsNotify/ ├── setup.cfg ├── setup.py └── src ...

Working with sequential workflow in CircleCI

With the help of Real Python, I've learned about continuous integration through CircleCI. I wrote this config.yml file based off of the RP Tutorial: version: 2 jobs: build: docker: -...

Docker sqlite3.OperationalError: unable to open database file

I know there are more similar questions but none of them solve the problem that I am having. I have assembled a very basic Python application with Flask: from flask import Flask app =...

Unable to connect to postgres database from django while running pytest

Django project and postgres are in different docker containers. I want to write the unit test cases for this application using pytest. I have implemented test cases using APIClient() along with...

NameError: name '_mysql' is not defined -- On airflow start in MacOSX

There are numbers of articles on the titled question but none of them worked for me. The detailed error is as follows: Traceback (most recent call last): File...

How to ignore certain scripts while testing flask app using pytest in gitlab CI/CD pipeline?

I have a flask-restx folder with the following structure . ├── app │   ├── extensions.py │   ├── __init__.py │   └── pv_dimensioning │   ├──...

ERROR: file not found when using pytest with VSCode (macOS)

I am trying to run a single unit test within VSCode by clicking Run Test (or Debug Test) above the unit test in the editor field, but I keep getting an ERROR: file not...

How can I get torch-geometric to work using Nix?

I am trying to get the Python package torch-geometric to work using Nix (I am on NixOS). Currently, I use mach-nix to try and setup a Python environment. However, the difficulty is that some of...

Append pytest coverage to file in Gitlab CI artifacts

I am trying to split my pytests in a gitlab stage to reduce the time it takes to run them. However, I am having difficulties getting the full coverage report. I am unable to use pytest-xdist or...

Attempting to run pytest and tox raises ModuleNotFoundError

I'm having issues testing my package with pytest and tox. When attempting to run both I receive ModuleNotFoundError. Pytest does find test_hello.py but fails immediate on trying to import my...