Repository: dynaconf/dynaconf

Issue:
How to use dynaconf in pytest when declared custom settings object
Hi. I need to override the environment for settings in conftest.py. As I found I can do it by adding:

```python
from dynaconf import settings


@pytest.fixture(scope="session", autouse=True)
def set_test_settings():
    settings.configure(FORCE_ENV_FOR_DYNACONF="testing")
```


but in my case I' ve got my own settings object under in the `confg.py` module and it looks like this:
```python
settings = Dynaconf(
    envvar_prefix='MY_PREFIX',
    settings_files=['settings.toml', '.secrets.toml'],
    environments=True,
    env_switcher='ENVIRONMENT_NAME',
)
```

and when I'm trying to do 

```python
from config import settings


@pytest.fixture(scope="session", autouse=True)
def set_test_settings():
    settings.configure(FORCE_ENV_FOR_DYNACONF="testing")
```

it does not work. It only overrides settings imported directly from dynaconf module. This is a problem because in my app I'm using settings from my `config.py` and my tests are failing when I override settings from `dynaconf` and use `from dynaconf import settings` in tests - because in app I'm using `from config import settings`




Discussion:

Resolving patch:
diff --git a/dynaconf/base.py b/dynaconf/base.py
--- a/dynaconf/base.py
+++ b/dynaconf/base.py
@@ -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:


Test patch:
diff --git a/tests_functional/issues/728_pytest/Makefile b/tests_functional/issues/728_pytest/Makefile
new file mode 100644
--- /dev/null
+++ b/tests_functional/issues/728_pytest/Makefile
@@ -0,0 +1,4 @@
+.PHONY: test
+
+test:
+	pytest -sv tests.py
diff --git a/tests_functional/issues/728_pytest/config.py b/tests_functional/issues/728_pytest/config.py
new file mode 100644
--- /dev/null
+++ b/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,
+)
diff --git a/tests_functional/issues/728_pytest/settings.toml b/tests_functional/issues/728_pytest/settings.toml
new file mode 100644
--- /dev/null
+++ b/tests_functional/issues/728_pytest/settings.toml
@@ -0,0 +1,8 @@
+[default]
+name = "default name"
+
+[development]
+name = "development name"
+
+[testing]
+name = "testing name"
diff --git a/tests_functional/issues/728_pytest/tests.py b/tests_functional/issues/728_pytest/tests.py
new file mode 100644
--- /dev/null
+++ b/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"