Opened 16 years ago

Closed 12 years ago

#9156 closed New feature (needsinfo)

Make tests self-contained

Reported by: Pablo Fernandez 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 by Russell Keith-Magee, 16 years ago

Component: UncategorizedTesting framework
Needs tests: set
Triage Stage: UnreviewedSomeday/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 by Luke Plant, 13 years ago

Severity: Normal
Type: New feature

comment:3 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 by Aymeric Augustin, 12 years ago

Resolution: needsinfo
Status: newclosed

No concrete suggestion was made since Malcolm's comment.

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