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
121
votes
2 answers

How do you skip a unit test in Django?

How do forcibly skip a unit test in Django? @skipif and @skipunless is all I found, but I just want to skip a test right now for debugging purposes while I get a few things straightened out.
user798719
  • 9,619
  • 25
  • 84
  • 123
97
votes
2 answers

How to see which tests were run during Django's manage.py test command

After tests execution is finished using Django's manage.py test command only number of passed tests is printed to the console. (virtualenv) G:\Project\>python manage.py test Creating test database for alias…
Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162
78
votes
6 answers

What is the clean way to unittest FileField in django?

I have a model with a FileField. I want to unittest it. django test framework has great ways to manage database and emails. Is there something similar for FileFields? How can I make sure that the unittests are not going to pollute the real…
luc
  • 41,928
  • 25
  • 127
  • 172
66
votes
5 answers

How can I test binary file uploading with django-rest-framework's test client?

I have a Django application with a view that accepts a file to be uploaded. Using the Django REST framework I'm subclassing APIView and implementing the post() method like this: class FileUpload(APIView): permission_classes =…
Tore Olsen
  • 2,153
  • 2
  • 22
  • 35
64
votes
4 answers

Running django tutorial tests fail - No module named polls.tests

I'm playing with django 1.6 tutorial but i can't run tests. My project (name mydjango) and app structure (name is polls) are as shown below in a virtualenv. (.nja files are just created by ninja-ide the ide I'm using) . ├── __init__.py ├──…
bre
  • 890
  • 1
  • 7
  • 13
60
votes
6 answers

Django Unit Testing taking a very long time to create test database

For some time now, my unit testing has been taking a longer than expected time. I have tried to debug it a couple of times without much success, as the delays are before my tests even begin to run. This has affected my ability to do anything…
dkarchmer
  • 5,434
  • 4
  • 24
  • 37
36
votes
1 answer

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 setUp(self): user =…
joe
  • 8,383
  • 13
  • 61
  • 109
23
votes
2 answers

Change the default domain of Client() in unittest of Django

I am writing a unit test for Django views. class TestLog(unittest.TestCase): """Test for Contact""" def setUp(self): self.c = Client() try: self.bob = User.objects.create_user("mojo","b@example.com", "bmojo") …
Shashi
  • 2,137
  • 3
  • 22
  • 37
16
votes
3 answers

Django testing how to assert Redirect

With the folliwing code I get this wrong result : nose.proxy.AssertionError: 302 != 200 : Couldn't retrieve redirection page '/mes_dossiers/': response code was 302 (expected 200) what is wrong with my code ? #test.py from django.test import…
Brigitte Maillère
  • 847
  • 1
  • 9
  • 27
15
votes
2 answers

Unit tests fail after a Django upgrade

I am trying to bring a Django project from version 1.8 to 1.11. Pretty much everything seems to work fine except unit tests. We have a base test class inheriting from Django TestCase with a Tastypie mixin. The base class has some code in the setUp()…
Mad Wombat
  • 14,490
  • 14
  • 73
  • 109
14
votes
1 answer

How to add authentication token in header of `APIClient` in `django rest_framework test`

I am using oauth2_provider for my rest_framework. I am trying to write test case for my api. I have obtained an access token. But I am not able to authenticate user using access token in APIClient I am looking to get this curl command work with…
14
votes
3 answers

Django unit test client response has empty context

I have a unit test that's failing in an assertion that passes in another test in the same test case class. Here's the passing test: def test_home(self): c = Client() resp = c.get('/') self.assertEqual(resp.status_code, 200) …
Melissa Avery-Weir
  • 1,357
  • 2
  • 16
  • 47
12
votes
1 answer

Running py.test inside Dockerfile

I have this Dockerfile that contains a line RUN py.test -vv. FROM bitnami/python:3.6-prod #MORE DIRECTIVES RUN py.test -vv COPY . /files WORKDIR /files EXPOSE 8080 When I run docker-compose build, I am getting this error. Step 16/21 : RUN py.test…
James Arnold
  • 698
  • 3
  • 9
  • 22
12
votes
2 answers

How to change Tox command with command-line parameters

How do you append options to the command Tox runs by appending that option to Tox? Specifically, how do you run a specific Django unittest with Tox? I'm trying to wrap Tox around some Django unittests, and I can run all unittests with tox, which…
Cerin
  • 60,957
  • 96
  • 316
  • 522
11
votes
4 answers

django how to assert url pattern resolves to correct class based view function

I have a class based view class HomePage(View): def get(self, request): return HttpResponse('

This is content.

') and url-pattern defined as below: urlpatterns = patterns('', url(r'^$', HomePage.as_view()), …
surenyonjan
  • 2,097
  • 3
  • 17
  • 26
1
2 3
21 22