MobileDynasty / pytest-env

pytest plugin used to set environment variables
MIT License
217 stars 23 forks source link

doesn't work well with pytest-django settings #3

Closed fletom closed 7 years ago

fletom commented 7 years ago

pytest-django's pytest_load_initial_conftests method, which imports the Django settings file, runs before pytest-env's pytest_load_initial_conftests

that means that any environment variables which are used in the Django settings module will not be set from pytest-env

is there any way to make sure that pytest-env runs first?

nourspace commented 7 years ago

@fletom have you figured a way around this?

The issue is being discussed here without a resolution so far https://github.com/pytest-dev/pytest/issues/935

fletom commented 7 years ago

sorry, I couldn't find a nice way to do it so I ended up doing what I wanted without an environment variable at all

Schnouki commented 7 years ago

After reading pytest-dev/pytest#935 and https://docs.pytest.org/en/latest/writing_plugins.html#hook-function-ordering-call-example, I tried something very simple: I added @pytest.hookimpl(tryfirst=True) to pytest_load_initial_conftests (in plugin.py)... and it works for me, I can set my environment variables before Django settings are loaded 😃

I'll send a PR as soon as possible.

jensneuhaus commented 7 years ago

Thanks for the report, @Schnouki - I run into this as well. It would be cool, if the PR can be merged :)