[TIP] pytest + Django: Where to put the test settings.py?

Jakub Vysoky jakub at borka.cz
Sun Mar 23 17:39:01 PDT 2014

i am not a pytest user (using nosetests mostly), but what i do for
testing stuff in general is this:

instead of `tests` directory i create another package called
`test_mypackage`, this one has `__init__.py` file because otherwise it
would not be a package ;))) and you can do any imports - say: `import

now it is really up to you, whether you will install `test_mypackage`
with `mypackage` as well or not (and i won't blame you for any


ps: i believe the only reason why not to make `tests` a package is
that there can be more of them on `sys.path` and you never know, which
one you will get. it happened to us while developing multiple
libraries/projects in one virtualenv - so we've switched from tests ->
test_mypackage, and it seems to work pretty well

also i am [1] not the only one [2] who is doing it - and there are
much more private repositories...

[1] https://github.com/kvbik/rehab
[2] https://github.com/elasticsearch/elasticsearch-py

On Sun, Mar 23, 2014 at 11:44 PM, Tin Tvrtković <tinchester at gmail.com> wrote:
> Hi everyone,
> this little project of mine (https://github.com/Tinche/bower-cache) uses
> Django, together with pytest for testing. I use the first layout from
> http://pytest.org/latest/goodpractises.html; a separate top-level directory
> for tests, and I'd like to keep my test data and the actual app code
> separate.
> I do, however, need a valid Django settings.py in order to run the tests. My
> first instinct was to put it into the tests directory and refer to it as
> tests.settings in my pytest.ini, but this doesn't work unless I make the
> tests directory a proper Python package (with __init__.py) which pytest
> explicitly suggests to avoid. The other option would be to put it somewhere
> into the app itself, but then this means I'm mixing test and normal code,
> which is something I'm trying to avoid in the first place.
> I was wondering if there was a generally-accepted way of solving this
> problem. Any advice from the community would be appreciated. :)
> Thanks in advance,
> Tin
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python

Jakub Vysoky

mob: +420 605 852 377
jab: jakub.vysoky at gmail.com
twit: https://twitter.com/kvbik

More information about the testing-in-python mailing list