py.test Tracebacks: Highlight my code, fold frames of framework

Tracebacks of my tests are too long since I use pytest. Pytests includes surrounding code lines and a lot of other information. I like to see this information if the traceback line (frame) is from...

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

How to install cffi package on AWS Beanstalk

This question looks the same as this post, but since there was no answer, I am re-asking here. I have a Django project to be deployed on AWS Beanstalk, which is using a package cffi. When I run eb...

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

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

Django Pytest Test URL Based on Settings

I have an endpoint /docs in django that I only want to be visible when DEBUG = True in settings - otherwise, it should throw a 404. My setup looks like this urls.py urlpatterns = ... if...

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

Failed building wheel for xmlsec - mac

I'm installing my mac on python virtualenv environment. Whenever I install requirement packages command "pip install -r requirements.txt" i got this messages. pip install -r requirements.txt...

VS Code not finding pytest tests

I have PyTest setup in vs-code but none of the tests are being found even though running pytest from the command line works fine. (I'm developing a Django app on Win10 using MiniConda and a Python...

How to access django database with pytest

I am wanting to use pytest with django to test api queries. Is there any way to do this in pytest without resorting to creating a test database? Pytest keeps throwing an error that database access...

pytest setup_class method and db access

import pytest from . import utilization pytestmark = pytest.mark.django_db some_period = 'test' @pytest.mark.django_db class TestUtilization(object): @classmethod def...

How to test views with pytest whose views has LoginRequired and some specific user dependencies

I am testing a view and while testing this I am getting this error self = <django.db.models.fields.AutoField: id>, value = '' def get_prep_value(self, value): from...

Mocking a RelatedManager in Django 2

This question is directly related to this question, but that one is now outdated it seems. I am trying to test a view without having to access the database. To do that I need to Mock a...

PIP randomly fails 'Could not find a version that satisfies the requirement' with the same requirements.txt

As part of our CI testing we install a virtualenv with some pip packages from a constant requirements.txt file. this installation process randomly fails from time to time with no apparent reason...

Run Django tests in the VSCode Test explorer?

I am trying to run Django unit tests in the VSCode Test Explorer, also, I want the CodeLens 'Run Tests' button to appear above each test. enter image description here However, in the Test...

Database is cleaned up after each test in pytest-django

What I am trying to achieve. I am testing rest API in Django project. I want to create test class with test functions that are related (each following test function relies on previous one) - first...

ModuleNotFoundError when trying to use mock.patch on a method

My pytest unit test keeps returning the error ModuleNotFoundError: No module name billing. Oddly enough the send_invoices method in the billing module is able to be called when I remove the patch...

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

How to call pytest-django from python manage.py test?

I have made my custom management command called pytest_wrp So when I call python manage.py test This bit of code is called: class Command(test.Command): def handle(self, *args, **options): ...

How to mock django settings attributes in pytest-django

When using Django default unittest it's trivial to patch settings attributes (using @override_settings decorator for instance.) I'd like to override several attributes of my settings for a test...

django-pytest is not using configs mentioned in pytest.ini

I am using pytest-django for the unit test cases for my django app. I have created pytest.ini in the root directory (same level as manage.py) with the following...

How to use pytest fixtures with django TestCase

How can I use a pytest fixture within a TestCase method? Several answers to similar questions seem to imply that my example should work: import pytest from django.test import TestCase from...

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

VSCode pytest test discovery fails when debugging Django tests

I'm trying to debug my first django test, but VSCode is returning: Ran 0 tests in 0.000s. On the other hand, when I use an integrated git bash (I'm using a windows OS) in VSCode terminals or...

Django Pytest parallel run - Database does not exist

I am using pytest to run my django tests and was trying to speed them up by running them in parallel. I tried modifying my database name using the enviroment variable PYTEST_XDIST_WORKER but my...

Pytest errors connecting to test database

I am running into strange errors I have never seen before running pytest where I am running my tests and nearly all are erroring out due to not being allowed to access the database. This is a new...

How to solve PytestConfigWarning: Unknown config option: DJANGO_ SETTINGS_MODULE error?

I am using django to build my website and I have used django-pytest to test my apps but I have got this error Note I am usign python...

After installing Django with poetry it says "No module named django" in active venv

I'm playing with poetry because I'm thinking about switching from pip. Following the basic usage examples, I'm doing the following: $ poetry new poetry-demo $ cd poetry-demo $ poetry add...

Django Pytest image upload image unit test

I'm using Django 3.2.6, django-pytest, and factory boy to run automated tests. This is the function I use to make a test image: from PIL import Image from django.core.files.uploadedfile import...

Django DatabaseError Invalid connector for timedelta

Previously, I did implement the ExpressionWrapper to create a custom filter, It's working fine in the postgresql, but when I did run test with sqlite3, then the error said...