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

Chris Jerdonek chris.jerdonek at gmail.com
Mon Mar 24 15:58:36 PDT 2014


My approach to Django's settings.py is to use a single settings.py for
the project, and to have the settings.py file read from a YAML file
for environment-specific values wherever necessary.  The path to the
YAML file is read from an environment variable, so when developing and
testing, you can set this environment variable to whatever is needed
prior to calling `python manage.py`, etc.

One benefit of this approach is that it lets the settings code be more
DRY across environments.

--Chris



On Sun, Mar 23, 2014 at 3: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



More information about the testing-in-python mailing list