Code

Opened 2 years ago

Closed 2 years ago

#18199 closed New feature (wontfix)

A way to have Django apps specific test runners

Reported by: maraujop Owned by: nobody
Component: Testing framework Version: 1.4
Severity: Normal Keywords: tests, testrunner, testing
Cc: miguel.araujo.perez@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi,

I maintain an application named <a href="https://github.com/maraujop/django-rules">django-rules</a> that for testing has a an app specific test runner, named runtests.py.

I got <a href="https://github.com/maraujop/django-rules/issues/10">this ticket openned</a>. When testing django-rules through the common approach python manage.py test django_rules it breaks. This is because running tests this way, Django autodetects my TestCases but doesn't use the runner itself, which has some test preparation (custom settings, real models only for testing).

Apparently there is no way to tell Django to use my runner for running tests, and Django doesn't automatically use the runner either. I could probably adapt my test suite to use new @override_setting decorator and mock objects. But the behavior I'm testing is very specific and attached to models itself.

What do you think? seems a reasonable use case?

Cheers

Attachments (0)

Change History (2)

comment:1 Changed 2 years ago by akaariai

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

For the settings part there is already @override_setting.

I discussed with maraujop about this issue in IRC. The problem is that a reusable app needs models for testing. Having them in models.py will create them also into production databases. I tried to find a clean way to have the models only available for testing, but could not find one.

I don't think having an app-specific test runner is the right way forward. The test runner is one level above the apps. I do think the use case is valid, as it would be nice to have models for testing without polluting the production database.

If there is already some way to achieve this then it should be documented. If this is already documented, then sorry for the noise. (I tried to look through the docs). Googling gave me this: http://stackoverflow.com/questions/502916/django-how-to-create-a-model-dynamically-just-for-testing, but this does not work for the reusable-app case.

comment:2 Changed 2 years ago by carljm

  • Resolution set to wontfix
  • Status changed from new to closed

Test-only models are already tracked by ticket #7835. This could be closed as duplicate of that, but since it specifically requested per-app test runners, which is something that isn't really feasible, I'm going to close wontfix.

I think the best practical solution here for reusable apps today is to put the tests in a different module (not appname.tests; perhaps appname.tests.tests) so that they aren't run at all by end-user projects, because there's very little value in that.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.