[TIP] Testing Django with py.test

Brent Hoover brent at autoshepherd.com
Tue Nov 1 13:04:42 PDT 2011

On 11/01/2011 12:55 PM, Brack, Laurent P. wrote:
> Not sure if this helps, but if I am not mistaken, Django (which I am 
> not familiar with) uses
> buildout.

Django does not use buildout. I believe the Django dev team does use 
buildout for their CI server, but it's no in any way part of the 
standard set up and I don't know a lot of Django people who are. Also, I 
don't use it either as virtualenv and a pip requirements.txt gives me 
everything I need. Not against using whatever is required to get a good 
environment, but seems like an awful large amount of ramp-up to just 
have a couple hooks. Though it would probably have other advantages I am 
not aware of.
> 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).
> [buildout]
> parts= pytest
> find-links = http://testlink.eng.dolby.net:8080
> [pytest]
> recipe = zc.recipe.egg
> eggs = PyTL
>        pytest
>        pytest-xdist
>        pytest-cov
>        pytest_testlink
>        ${project:eggs}
> 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.
> -----Original Message-----
> 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
> Hello,
> 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.
> --
> Brent Hoover
> Senior Web Application Developer
> AutoShepherd.com
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python

Brent Hoover
Senior Web Application Developer

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20111101/917114bb/attachment.htm>

More information about the testing-in-python mailing list