django-lazysignup icon indicating copy to clipboard operation
django-lazysignup copied to clipboard

Run tests only if using test settings.

Open mitar opened this issue 14 years ago • 9 comments
trafficstars

Currently tests are always run. Now they are skipped if they are not run with test settings. This allows running tests for many applications at the same time (./manage test).

Probably this can be improved once Django 1.4 lands as it supports custom settings for tests. (Although custom model probably has to be configured before test database is setup.)

mitar avatar Oct 31 '11 22:10 mitar

I've actually added a separate test project so you can run the tests without needing your own project already set up. This seems to be the way several other 3rd party apps have gone. I'll definitely review when 1.4 lands though.

danfairs avatar Nov 03 '11 16:11 danfairs

OK, but tests should also not fail (can be skipped) if you run all tests available in a project.

mitar avatar Nov 03 '11 18:11 mitar

Hm, all tests are currently being skipped if I run them with a given test project. This is probably not a feature. ;-)

mitar avatar Nov 03 '11 18:11 mitar

Hah! That's what you get for coding with a baby in one arm! :)

danfairs avatar Nov 03 '11 20:11 danfairs

Congrats that it does run then!

mitar avatar Nov 03 '11 21:11 mitar

Actually - running python manage.py test in the testproject directory does run the lazysignup tests, in amongst the tests for the other Django apps. For me, they appear (bizarrely, I'm not sure how the Django test runner orders tests) in the middle of django.contrib.session tests.

What do you see when you run:

python manage.py test -v2

?

danfairs avatar Nov 04 '11 10:11 danfairs

OK. My mistake. It picked my old version of django-lazysignup. OK, so this testproject works. But django-lazysignup tests are still run if I run all tests for my project. And they fail. I would argue that they should succeed or be skipped.

mitar avatar Nov 04 '11 22:11 mitar

Yes, they should - though I don't like the idea of adding a setting to do it. Lazysignup already has its fair share! And I don't recall seeing that pattern used anywhere else.

I think the proper fix is improve the test isolation from the settings being used. For example, I'm guessing that the failures you're seeing are 404s, as the test urls aren't used - I should be using the urls = feature in the test case body. (Ironically, I used to do this, but removed it when I added the test project!)

It's not as small a fix as your original pull request, but I feel it's the correct way. Does that sound reasonable?

danfairs avatar Nov 04 '11 22:11 danfairs

I am getting those failures:

Creating test database for alias 'default'...
.F..E..F.FFFF.FFF..F.FE.....FF....FFF.
======================================================================
ERROR: test_bad_custom_convert_form (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 323, in test_bad_custom_convert_form
    reverse('test_bad_convert'), {
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 391, in reverse
    *args, **kwargs)))
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 337, in reverse
    "arguments '%s' not found." % (lookup_view_s, args, kwargs))
NoReverseMatch: Reverse for 'test_bad_convert' with arguments '()' and keyword arguments '{}' not found.

======================================================================
ERROR: test_good_custom_convert_form (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 331, in test_good_custom_convert_form
    self.client.post(reverse('test_good_convert'), {
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 391, in reverse
    *args, **kwargs)))
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 337, in reverse
    "arguments '%s' not found." % (lookup_view_s, args, kwargs))
NoReverseMatch: Reverse for 'test_good_convert' with arguments '()' and keyword arguments '{}' not found.

======================================================================
FAIL: test_authenticated_user_class (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 440, in test_authenticated_user_class
    self.assertEqual(CustomUser, type(request.user))
AssertionError: <class 'lazysignup.tests.CustomUser'> != <class 'project.account.models.LazyUser'>

======================================================================
FAIL: test_banned_user_agents (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 144, in test_banned_user_agents
    self.failIf(hasattr(self.request, 'user'))
AssertionError: True is not false

======================================================================
FAIL: test_convert_ajax (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 197, in test_convert_ajax
    self.assertEqual(200, response.status_code)
AssertionError: 200 != 405

======================================================================
FAIL: test_convert_anon (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 78, in wrapped
    result = func(*args, **kwargs)
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 301, in test_convert_anon
    self.assertEqual(302, response.status_code)
AssertionError: 302 != 404

======================================================================
FAIL: test_convert_existing_user_ajax (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 279, in test_convert_existing_user_ajax
    self.assertEqual(400, response.status_code)
AssertionError: 400 != 405

======================================================================
FAIL: test_convert_existing_user_no_ajax (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 289, in test_convert_existing_user_no_ajax
    self.assertEqual(302, response.status_code)
AssertionError: 302 != 405

======================================================================
FAIL: test_convert_mismatched_no_ajax (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 254, in test_convert_mismatched_no_ajax
    self.assertEqual(200, response.status_code)
AssertionError: 200 != 405

======================================================================
FAIL: test_convert_mismatched_passwords_ajax (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 230, in test_convert_mismatched_passwords_ajax
    self.assertEqual(400, response.status_code)
AssertionError: 400 != 405

======================================================================
FAIL: test_convert_non_ajax (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 217, in test_convert_non_ajax
    self.assertEqual(302, response.status_code)
AssertionError: 302 != 405

======================================================================
FAIL: test_decorated_view (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 158, in test_decorated_view
    self.assertEqual(200, response.status_code)
AssertionError: 200 != 404

======================================================================
FAIL: test_get_convert (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 294, in test_get_convert
    self.assertEqual(200, response.status_code)
AssertionError: 200 != 404

======================================================================
FAIL: test_no_lazysignup_decorator (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 78, in wrapped
    result = func(*args, **kwargs)
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 317, in test_no_lazysignup_decorator
    self.assertEqual(500, response.status_code)
AssertionError: 500 != 404

======================================================================
FAIL: test_normal_view (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 151, in test_normal_view
    self.assertEqual(200, response.status_code)
AssertionError: 200 != 404

======================================================================
FAIL: test_user_exists_ajax (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 244, in test_user_exists_ajax
    self.assertEqual(400, response.status_code)
AssertionError: 400 != 405

======================================================================
FAIL: test_user_exists_no_ajax (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 268, in test_user_exists_no_ajax
    self.assertEqual(200, response.status_code)
AssertionError: 200 != 405

======================================================================
FAIL: test_user_field (lazysignup.tests.LazyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mitar/Library/python/modules/lazysignup/tests.py", line 431, in test_user_field
    self.assertEqual(CustomUser, LazyUser.get_user_class())
AssertionError: <class 'lazysignup.tests.CustomUser'> != <class 'project.account.models.LazyUser'>

----------------------------------------------------------------------
Ran 38 tests in 1.338s

FAILED (failures=16, errors=2)
Destroying test database for alias 'default'...

Sadly, I doubt that urls = itself will help. Because I was getting such failures already before, when it was in the effect. I think there is no easy solution until Django 1.4. So I think this internal setting (used only in settings in testproject) is the easiest way. With a TODO comment for Django 1.4. ;-)

mitar avatar Nov 04 '11 22:11 mitar