Opened 7 years ago

Closed 3 years ago

#9156 closed New feature (needsinfo)

Make tests self-contained

Reported by: pupeno Owned by: nobody
Component: Testing framework Version: 1.0
Severity: Normal Keywords:
Cc: Triage Stage: Someday/Maybe
Has patch: no Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello,

It would be nice if Django tests, both tests created by users using Django and the Django tests themselves were self-contained in the sense that any test could be run on it's own. This can be achieved by a mix of default settings and using extensively the set up and tear down. I've done it in other projects with similarly complex tests.

Thanks.

Change History (5)

comment:1 Changed 7 years ago by russellm

  • Component changed from Uncategorized to Testing framework
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Someday/Maybe

Wouldn't it be great if things were better! Well, yeah, sure... now tell us how to make things better. Preferably in the form of a patch.

The default settings approach doesn't really work, because normal website operation has different configuration requirements to test operation. Unless you're using a custom test runner (like, say, ./manage.py test), there is no way to differentiate the two configuration requirements.

It would be possible to do this using setup() and teardown(), but this would mean that every single setup and teardown method would need to include some common code. Code duplication==bad.

You could do this using subclasses of unittest.TestCase, but then that would prevent you from using the stock unitest.TestCase easily.

The setup/teardown-based suggestions also neglect to provide a solution for doctests, which form a significant portion of the Django test suite.

The only simple approach I can see would be to define a if name == 'main' block on each test file that makes the relevant calls to set up the test environment. This is slightly less code duplication that defining a setup() and teardown(), but still a lot of duplication. With some effort, we might be able to make this a very simple piece of setup, though.

Any other suggestions are welcome. Marking this as someday/maybe until a concrete suggestion is made.

comment:2 Changed 4 years ago by lukeplant

  • Severity set to Normal
  • Type set to New feature

comment:3 Changed 4 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 4 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:5 Changed 3 years ago by aaugustin

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

No concrete suggestion was made since Malcolm's comment.

Note: See TracTickets for help on using tickets.
Back to Top