question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynaconf can't find settings file when using pytest

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
trallnagcommented, Jul 27, 2020

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

2reactions
vbrinzacommented, 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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynaconf can't find settings file when using pytest #374 - GitHub
It seems like Dynaconf is looking for the files in the tree the python command was invoked from and not relative the module...
Read more >
Testing β€” dynaconf 2.2.3 documentation - Read the Docs
For pytest it is common to create fixtures to provide pre-configured settings object or to configure the settings before all the tests are...
Read more >
Settings files - Dynaconf - 3.1.11
Settings file location ΒΆ ... Dynaconf will search files specified in settings_file option starting the search tree on the current working dir (theΒ ......
Read more >
Are config settings loaded separately into each Python ...
In this answer, I was told that the logger needed to only be declared once globally. On similar lines, how are program configuration...
Read more >
Settings and Environment Variables - FastAPI
But a dotenv file doesn't really have to have that exact filename. Pydantic has support for reading from these types of files using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found