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

Dynaconf can't find settings file when using pytest #374

Closed
trallnag opened this issue Jul 27, 2020 · 9 comments
Closed

Dynaconf can't find settings file when using pytest #374

trallnag opened this issue Jul 27, 2020 · 9 comments
Labels

Comments

@trallnag
Copy link

Where do I put settings files / How do I configure Dynaconf so it will work with pytest? Currently I get the following error:

AttributeError: 'Settings' object has no attribute 'LOGGING'

It seems like Dynaconf is looking for the files in the tree the python command was invoked from and not relative the module itself.

Here is how my project structure (simplified) looks like:

.
├── ...
├── project
│   ├── app.py
│   ├── conf.py
│   ├── __init__.py
│   ├── settings.toml
└── tests
    ├── conftest.py    
    └── test_app.py

My conf.py:

from dynaconf import Dynaconf

settings = Dynaconf(
    envvar_prefix="DYNACONF", settings_files=["settings.toml", ".secrets.toml"],
)

Thanks in advance

@trallnag
Copy link
Author

Oh well I found a solution.

import os

from dynaconf import Dynaconf

current_directory = os.path.dirname(os.path.realpath(__file__))

settings = Dynaconf(
    envvar_prefix="DYNACONF", settings_files=[f"{current_directory}/settings.toml", f"{current_directory}/.secrets.toml"],
)

I will keep this issue open for a bit, maybe I can get feedback if this is an appropriate solution or not

@MarcoAlejandro
Copy link

It worked for me. Thanks @trallnag

@LeafwaysWorks
Copy link

worked thanks

@rochacbruno
Copy link
Member

You can also do

import os

from dynaconf import Dynaconf

current_directory = os.path.dirname(os.path.realpath(__file__))

settings = Dynaconf(
    root_path=current_directory,
    envvar_prefix="DYNACONF", 
    settings_files=["settings.toml", ".secrets.toml"],
)

@vbrinza
Copy link

vbrinza commented Oct 3, 2022

Does it mean we need a fix in the documentation so the others who start working with it do not have to spend few ours figuring it out as I did?

@rochacbruno
Copy link
Member

@vbrinza yes that would be great to add that to the docs https://www.dynaconf.com/advanced/#testing

@mababio
Copy link

mababio commented Oct 4, 2022

Ah thanks for the solution!! ... i was 2 hours into debugging

@vbrinza
Copy link

vbrinza commented Oct 9, 2022

@rochacbruno please take a look at my PR #819

@sayurionishi
Copy link

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants