How to tell whether the current module is loaded under `manage.py test`

0 views
Skip to first unread message

Alex Dong

unread,
Nov 25, 2009, 3:10:04 AM11/25/09
to Django users
Hi all,

During the `manage.py test` process, django will automatically change
the database from `hivemind` to `test_hivemind`, For similar reason,
I'd like to change a file path from `sphinx.conf` to
`sphinx_test.conf` but unfortunately I couldn't find a proper way to
do it.

Ideally, if there is a django method called `django.test.is_testing()
`, then I should be able to change the filename based on the return
value. Any hints on how I could do this?

Cheers,
Alex

Russell Keith-Magee

unread,
Nov 25, 2009, 6:27:56 PM11/25/09
to django...@googlegroups.com
You shouldn't.

Code shouldn't be aware that it is being run in a test. Introducing
'if TESTING' branches into code introduces extra complexity into the
code you are trying to test - complexity that, by definition, is
untestable.

If you need to modify a setting for testing purposes, then do the same
thing that the Django test suite does - in your test setUp() method,
modify the value of the setting, then restore the original value
during tearDown().

Yours,
Russ Magee %-)
Reply all
Reply to author
Forward
0 new messages