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

How to use dynaconf in pytest when declared custom settings object #728

Closed
mzebrak opened this issue Mar 29, 2022 · 1 comment · Fixed by #809
Closed

How to use dynaconf in pytest when declared custom settings object #728

mzebrak opened this issue Mar 29, 2022 · 1 comment · Fixed by #809
Labels
Milestone

Comments

@mzebrak
Copy link

mzebrak commented Mar 29, 2022

Hi. I need to override the environment for settings in conftest.py. As I found I can do it by adding:

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:

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

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

@rochacbruno rochacbruno modified the milestones: 3.2.0, 3.1.8 Mar 31, 2022
@rochacbruno rochacbruno modified the milestones: 3.1.9, 3.2.0 Jun 2, 2022
@rochacbruno
Copy link
Member

Fixed and added a test https://github.com/dynaconf/dynaconf/pull/809/files

rochacbruno added a commit that referenced this issue Sep 22, 2022
Shortlog of commits since last release:

    Amadou Crookes (1):
          envars.md typo fix (#786)

    Bruno Rocha (19):
          Release version 3.1.9
          Bump dev version to 3.1.10
          Update badges
          demo repo will be replaced by a video tutorial soon
          Fix CI
          New data key casing must adapt to existing key casing (#795)
          Add test and docs about includes (#796)
          Removed vendor_src folder (#798)
          Replacing rochacbruno/ with dynaconf/ (#800)
          Fix codecov (#801)
          Parse negative numbers from envvar Fix #799 and Fix #585 (#802)
          Fix get command with Django (#804)
          Add a functional test runner (#805)
          Test runner docs and styling (#806)
          Allow merge_unique on lists when merge_enabled=True (#810)
          Rebind current env when forced for Pytest Fix #728 (#809)
          AUTO_CAST can be enabled on instance (#811)
          Ensure pyminify is on release script
          Add missing tomllib to monify script

    Gaurav Talreja (1):
          Fix #807 Use client.auth.approle.login instead of client.auth_approle (#808)

    Jitendra Yejare (1):
          Fix #768 of kv property depreciation from client object (#769)

    Joren Retel (2):
          Feature/detect casting comb token from converters (#784)
          Adding documentation and example to makefile. (#791)

    João Gustavo A. Amorim (1):
          Add pyupgrade hook (#759)

    Kian-Meng Ang (1):
          Fix typos (#788)

    Lucas Limeira (1):
          Using filter_strategy in env_loader to fix #760 (#767)

    Nicholas Nadeau, Ph.D., P.Eng (1):
          fix: typo (#766)

    Oleksii Baranov (2):
          Bump codecov action version (#775)
          Fix cli init command for flask (#705) (#774)

    Pedro de Medeiros (1):
          documentation fixes (#771)

    The Gitter Badger (1):
          Add a Gitter chat badge to README.md (#776)

    Théo Melo (1):
          Fixing a typo on the readme file (#763)

    Vicente Marçal (1):
          docs(pt-br): Docs Translation to brazilian portugues. (#787)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants