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

Rebind current env when forced for Pytest Fix #728 #809

Merged
merged 2 commits into from Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions dynaconf/base.py
Expand Up @@ -694,6 +694,7 @@ def current_env(self):
return self.MAIN_ENV_FOR_DYNACONF.lower()

if self.FORCE_ENV_FOR_DYNACONF is not None:
self.ENV_FOR_DYNACONF = self.FORCE_ENV_FOR_DYNACONF
return self.FORCE_ENV_FOR_DYNACONF

try:
Expand Down
4 changes: 4 additions & 0 deletions tests_functional/issues/728_pytest/Makefile
@@ -0,0 +1,4 @@
.PHONY: test

test:
pytest -sv tests.py
9 changes: 9 additions & 0 deletions tests_functional/issues/728_pytest/config.py
@@ -0,0 +1,9 @@
from __future__ import annotations

from dynaconf import Dynaconf

settings = Dynaconf(
envvar_prefix="ISSUE728",
settings_files=["settings.toml", ".secrets.toml"],
environments=True,
)
8 changes: 8 additions & 0 deletions tests_functional/issues/728_pytest/settings.toml
@@ -0,0 +1,8 @@
[default]
name = "default name"

[development]
name = "development name"

[testing]
name = "testing name"
16 changes: 16 additions & 0 deletions tests_functional/issues/728_pytest/tests.py
@@ -0,0 +1,16 @@
from __future__ import annotations

import pytest
from config import settings


@pytest.fixture(scope="session", autouse=True)
def set_test_settings():
settings.configure(FORCE_ENV_FOR_DYNACONF="testing")
assert settings.current_env == "testing"


def test_running_on_testing_environment():
assert settings.current_env == "testing"
assert settings.ENV_FOR_DYNACONF == "testing"
assert settings.NAME == "testing name"