Questions tagged [django-unittest]

django-unittest tag refers to writing unit tests in Django, tests that are expressed as methods on a Python class that subclasses unittest.TestCase or Django's customized TestCase.

django-unittest tag refers to writing unit tests in Django, tests that are expressed as methods on a Python class that subclasses unittest.TestCase or Django’s customized TestCase.

329 questions
6
votes
1 answer

PEP8 for long method's name

What is the PEP8 correct way for long method's name? I have a unit test with a self-describing method: def success_if_buying_price_item_when_participating_and_progression_is_100_percent(self): But unfortunately this (too long?) method reaches the…
bagage
  • 1,094
  • 1
  • 21
  • 44
6
votes
3 answers

django - HttpRequest object has no attribute 'session'

I can't seem to get sessions working. Django complains that HttpRequest objects have no attribute called 'session'. In the documentation it clearly states that if you have the middleware enabled, and the django.contrib.sessions in your installed…
Max Clarke
  • 1,148
  • 2
  • 11
  • 19
6
votes
3 answers

How can I get Python's unittest to not catch exceptions?

I'm working on a Django project but I think this is a pure Python unittest question. Normally, when you run tests, exceptions will be caught by the test runner and handled accordingly. For debugging purposes, I want to disable this behavior, i.e. so…
Ghopper21
  • 10,287
  • 10
  • 63
  • 92
5
votes
1 answer

Writing Django signup form tests for checking new user creation

Implemented a custom user model in Django and allows user to signup using the url http://127.0.0.1:8000/users/signup/. A GET request on this url is displayed like this: I have written tests for this page. Tests for get is working as expected. I…
nitin_cherian
  • 6,405
  • 21
  • 76
  • 127
5
votes
1 answer

How to fix "TypeError: argument of type 'ConnectionHandler' is not iterable" when running a django test?

When I do ```python -m unittest`` inside of my users app, I get this error: TypeError: argument of type 'ConnectionHandler' is not iterable I was customizing my User model in django and I wanted to make a test for it. I already did the migrations…
5
votes
1 answer

ValueError: No module named 'notmigrations' during unit tests

I have django application 2.1.7 with django-tenant plugin (creating schemas in the database for saas). My problem is unit testing. I run the command: python manage.py test --settings=project.settings_test and I'm getting a error: ImportError: No…
5
votes
0 answers

How/why do unit tests affect each other in a TestCase and how to prevent this behaviour?

I am writing tests for a webapp that is made in Python3.6/Django 2.0 and I have the following situation: class TestFoo(TestCase): def test_a(self): obj = Foo.objects.create(a = "bar") expectation = {"a" : "bar"} …
Don
  • 115
  • 8
5
votes
1 answer

How to unittest Django admin inline forms

How do you use Django's unittesting Client to fill in inline forms? In my test, I've tried: response = client.get('/admin/myapp/prospect/add/') initial = response.context['adminform'].form.initial initial['name'] = 'Jon Doe' response =…
Cerin
  • 60,957
  • 96
  • 316
  • 522
5
votes
1 answer

pytest-django database initialization doesn't appear to reload the database

We have distilled a situation down to the following: import pytest from django.core.management import call_command from foo import bar @pytest.fixture(scope='session') def django_db_setup(django_db_setup, django_db_blocker): LOGGER.info('ran…
peter
  • 81
  • 2
  • 5
5
votes
1 answer

Mocking patched class methods is not working

I'm using Django with DRF and python mock. What I am trying to do is to test my views and mock a serializer and some methods. This is what I have: views.py from gmm_mobile.v1.serializers import RegisterParticipationSerializer from…
5
votes
2 answers

django.test.client got 404 error on existing url

I just started learning unittests and stuck with this problem. I got project structure like this (it’s Django 1.6.2…
anti1869
  • 1,219
  • 1
  • 10
  • 18
5
votes
1 answer

How to test Django redirect from view class

I'm learning Django atm and I am stuck with creating a simple test case. How I can test the following view? If the user is already logged in it redirects him to list view. from django.shortcuts import render from django.contrib.auth import…
Sh1d0w
  • 9,340
  • 3
  • 24
  • 35
4
votes
2 answers

Inspecting django unittest errors in pdb

I have a unittest that throws an exception. The exception isn't thrown by my code, it's from somewhere deep within django. I want to open a pdb session at that spot and see what's the haps, but when I open ipython with pdb and run test myapp the…
pseudosudo
  • 6,270
  • 9
  • 40
  • 53
4
votes
1 answer

How to set headers in DRF's APIClient() delete() request?

When running tests, I'd like to create and then delete some resources. Access to the target server requires authenticating with a token. from django.test import TestCase from rest_framework.test import APIClient (...) class MyTest(TestCase): …
AbreQueVoy
  • 1,748
  • 8
  • 31
  • 52
4
votes
0 answers

Django & coverage - .coveragerc omit not working

I have a Django project with multiple applications. In one application, I have a library already tested using unittest + coverage. When I run the test of the django project, I would like to omit this folder. My project architecture is : project/ ├──…
Nicolas M.
  • 1,472
  • 1
  • 13
  • 26
1 2
3
21 22