Add a NAV_CONFIG_DIR environment variable to override NAV configuration file search path#3697
Conversation
The NAV_CONFIG_DIR environment variable can be used to insert a custom directory as the first entry in the list of directories NAV will search for its config files. This would mostly be useful to manipulate where NAV code searches for configuration files during tests. Currently, the test suite sort of depends on tox and the manipulation of config files below the current virtualenv directory, but this is not conducive to running tests interactively during development, since it would cause tests to use the developer's currently active configuration files rather than a set created in a temporary directory for the tests.
Change any code that uses the `CONFIG_LOCATIONS` global variable directly to instead use the new `get_config_locations()` function.
This adds tests that will test the proper behavior when manipulating the `NAV_CONFIG_DIR` environment variable.
NAV_CONFIG_DIR environment variable to override NAV configuration files directory
NAV_CONFIG_DIR environment variable to override NAV configuration files directoryNAV_CONFIG_DIR environment variable to override NAV configuration file search path
|
Test results 27 files 27 suites 46m 1s ⏱️ Results for commit bdbcd25. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3697 +/- ##
=======================================
Coverage 63.07% 63.07%
=======================================
Files 612 612
Lines 45239 45245 +6
Branches 43 43
=======================================
+ Hits 28533 28537 +4
- Misses 16696 16698 +2
Partials 10 10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
hmpf
left a comment
There was a problem hiding this comment.
Both the function and the use of pathlib is an improvement!
johannaengland
left a comment
There was a problem hiding this comment.
Looks good, maybe the documentation that you added to the install guides can also be added to https://nav.readthedocs.io/en/latest/hacking/hacking.html#running-tests since you said it was to be used when running tests in the future
Not in this PR, since nothing in the test suite is affected by this yet. I have commits for future PRs that adds a config-dir fixture which can be used for configuration manipulation, and when I get around to making that work properly (with tests that show how to use it) would be the right time to add more docs. |
Goody, just didn't want that part to be forgotten :) |



Scope and purpose
The
NAV_CONFIG_DIRenvironment variable can now be used to insert a custom directory as the first entry in the list of directories NAV will search for its config files.This would mostly be useful to manipulate where NAV code searches for configuration files during tests. Currently, the test suite sort of depends on tox and the manipulation of config files below the current virtualenv directory, but this is not conducive to running tests interactively during development, since it would cause tests to use the developer's currently active configuration files rather than a set created in a temporary directory for the tests.
I.e. this PR adds the option both for users to manipulate this if needed, and lays the groundwork for the test suite to be able to more properly manipulate test configuration in isolated environments.
Contributor Checklist
Every pull request should have this checklist filled out, no matter how small it is.
More information about contributing to NAV can be found in the
Hacker's guide to NAV.
<major>.<minor>.x). For a new feature or other additions, it should be based onmaster.If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be doneIf it's not obvious from a linked issue, described how to interact with NAV in order for a reviewer to observe the effects of this change first-hand (commands, URLs, UI interactions)If this results in changes in the UI: Added screenshots of the before and afterIf this adds a new Python source code file: Added the boilerplate header to that file