Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
fletom opened this issue Feb 12, 2017 · 4 comments
Closed

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

fletom opened this issue Feb 12, 2017 · 4 comments

Comments

@fletom
Copy link

fletom commented Feb 12, 2017

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
Copy link

@fletom have you figured a way around this?

The issue is being discussed here without a resolution so far
pytest-dev/pytest#935

@fletom
Copy link
Author

fletom commented Feb 20, 2017

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
Copy link
Contributor

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.

Schnouki added a commit to Schnouki/pytest-env that referenced this issue Apr 28, 2017
This is required when other plugins (e.g. pytest-django) need to access environment variables set by this plugin.

Fixes MobileDynasty#3.
@jensneuhaus
Copy link

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

@lbud4 lbud4 closed this as completed in #4 Jun 7, 2017
jensneuhaus added a commit to pixelpassion/drf-saas-starter that referenced this issue Jul 31, 2017
Another problem came up regarding the STAGE=test flag, so that py.test runs with Whitenoise.

py.test environments are not loaded before django settings setup (check MobileDynasty/pytest-env#3). The pytest-env needs to be fixed but a PR is not accepted, I forked the repository and used that one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants