Questions tagged [pytest-django]

A plugin for pytest that simplifies testing of django projects.

Pytest-django is a plugin for pytest that helps with the testing of django projects. The package includes specialized fixtures for setting up/tearing down the development server and test client.

387 questions
7
votes
2 answers

force Django tests to write models into database

I am setting up a very simple Django project and with a very simple test like: def test_name(self): t = Thing.objects.create(name='a') print(t.id) import time time.sleep(30) self.assertEqual('a', t.name) The tests passes of…
eLRuLL
  • 18,488
  • 9
  • 73
  • 99
6
votes
1 answer

How to mark individual parameterized tests with a marker?

I have been trying to parameterize my tests using @pytest.mark.parametrize, and I have a marketer @pytest.mark.test("1234"), I use the value from the test marker to do post the results to JIRA. Note the value given for the marker changes for every…
Rekha R
  • 131
  • 1
  • 1
  • 12
6
votes
1 answer

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): super(Command, self).handle(*args, **options)…
6
votes
0 answers

How can I make citext extension work on Django tests?

I'm running tests against a model having a ArrayField(CICharField()) field and they return a string instead of a list. I use pytest-django to run the tests. I know that returning a string instead of a list was a known problem in the past, but it's…
barraquito
  • 168
  • 9
6
votes
1 answer

How to run tests in django using database with data?

I want to test my views using data from postgres localhost database (with already loaded data). I'm using tox with pytest and pytest-django. My question: How to set up / connect to local database to get all the data model schema and data itself? Or…
6
votes
1 answer

pytest exception none type object is not callable

In test1.py I have below code @pytest.fixture(scope="session") def moduleSetup(request): module_setup = Module_Setup() request.addfinalizer(module_setup.teardown()) return module_setup def test_1(moduleSetup): print moduleSetup …
user2661518
  • 2,677
  • 9
  • 42
  • 79
6
votes
2 answers

How to persist data to DB between tests with pytest-django?

How can I persist data to DB when using pytest/pytest-django in a test-run of a Django application? I run pytest with py.test --nomigrations --reuse-db -s and the Postgres DB test_ is created as expected, however nothing seems to…
OG Dude
  • 936
  • 2
  • 12
  • 22
5
votes
1 answer

Pytest-Cov Show Coverage For Untouched Files

When I run my tests, I realised that pytest-cov only shows coverage reports for files that are touched during the automated tests. How can I set it so that it shows coverage for even files that are not touched?
Daniel
  • 67
  • 1
  • 7
5
votes
2 answers

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 error that did not occur last week so it isn't a…
ViaTech
  • 2,143
  • 1
  • 16
  • 51
5
votes
1 answer

How can I use pytest-django to create a user object only once per session?

First, I tired this: @pytest.mark.django_db @pytest.fixture(scope='session') def created_user(django_db_blocker): with django_db_blocker.unblock(): return CustomUser.objects.create_user("User", "UserPassword") def…
superdee73
  • 353
  • 2
  • 13
5
votes
1 answer

Get overview of SQL query count for every test in a test suite

I have a large Django application with tons of tests that need SQL query optimizations. I'm using pytest-django to run my tests. I don't want to add assertNumQueries or django-assert-num-queries for each test individually, but instead produce an…
Wolkenarchitekt
  • 20,170
  • 29
  • 111
  • 174
5
votes
2 answers

Why do I get empty django querysets when using ThreadPoolExecutor with pytest-django?

I have been trying to track down some bugs in some concurrent code and wanted to write a test that ran a function in parallel. I am using Django with postgres as my database and testing using pytest and pytest-django. To run my function, I am using…
mattjegan
  • 2,724
  • 1
  • 26
  • 37
5
votes
1 answer

pytest-django: Is this the right way to test view with parameters?

Say I'm testing an RSS feed view in a Django app, is this how I should go about it? def test_some_view(...): ... requested_url = reverse("personal_feed", args=[some_profile.auth_token]) resp = client.get(requested_url, follow=True) …
zerohedge
  • 3,185
  • 4
  • 28
  • 63
5
votes
0 answers

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 setup_class(self): self.period = some_period …
DmitrySemenov
  • 9,204
  • 15
  • 76
  • 121
5
votes
2 answers

pytest-django add fixtures to live_server fixture

I need to add fixtures to the live_server fixture provided by pytest-django specifically an overwritten django_db_setup. That being said I understand it is not ideal to run tests against a db that isn't flushed clean but it is what I am working…
Adam
  • 3,992
  • 2
  • 19
  • 39
1 2
3
25 26