[TIP] Testing Django with py.test
Brack, Laurent P.
lpbrac at dolby.com
Tue Nov 1 12:55:41 PDT 2011
Not sure if this helps, but if I am not mistaken, Django (which I am not familiar with) uses
We use buildout internally in conjunction with PyTest and specify pytest, pytest-cov and pytest-xdist
as part of our buildout file (see excerpt below). After running buildout, we end up with a py.test file
in the ./bin folder which has all the system path set to the buildout environment (pytest_testlink is a plugin
linking pytest to a testlink server).
find-links = http://testlink.eng.dolby.net:8080
recipe = zc.recipe.egg
eggs = PyTL
Note: Xdist doesn't work for us at this time as we are not generating an interpreter as part of buildout but we are using the system one, hence instances of python started via execnet have no knowledge of the buildout environment. Should be easy to fix though via the xdist hooks.
From: testing-in-python-bounces at lists.idyll.org on behalf of Brent Hoover
Sent: Tue 11/1/2011 12:16 PM
To: testing-in-python at lists.idyll.org
Subject: [TIP] Testing Django with py.test
I apologize if this is an obvious question but I have searched in vain
for it for quite some time.
I currently have over to 400 tests on my Django project that no longer
work because I am doing a small bit of Postgresql-specific code (after a
lot of time trying to avoid it). So I have written a test runner and
test case that skips the the db creation/teardown and substitutes an
already in place, empty copy of the db.
The problem is that using my own runner I am back to the cruddy test
discovery that Django has and no reporting, coverage etc. I was using
django-nose but would like to switch to py.test but run into the simple
issue that I can't seem to figure out how to get py.test to run in the
Django-specific setup (e.g. inserting the project root into the front of
sys.path, importing settings, etc). So when I run my tests, py.test
finds them but all imports fail as the are all relative to the project
root. Making them absolute means nothing works when running the dev server.
Where would be the "hook" point for pytest so that it does the little
hacks to make this work? Is this a best written as a plugin or just
something I can somehow put in my py.test config file?
Your help would be very much appreciated.
Senior Web Application Developer
testing-in-python mailing list
testing-in-python at lists.idyll.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python