Repository navigation
✨ feat(config): merge nested pytest_env tables - #370
Merged
Merged
Conversation
In a monorepo one pytest configuration at the root serves several
subprojects, but pytest-env stops at the first pytest_env table it finds
walking up from the configuration directory, so a subproject's own table
is never read.
With merge_nested = true in that table, pytest-env also reads the tables
between it and each tested path and merges them from the top down. A
nested entry replaces the parent's entry for the same variable, flags
included, and each {VAR} template applies after the variables it names,
whichever table sets them, so a root URL template picks up a name a
subproject sets. Nested env_files load after the parent's, resolved from
their own directory, and a nested env_files_skip_if_set replaces the
parent's.
Paths that would read different tables in one run stop pytest with a
usage error, since they share one environment.
Closes #369
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In a monorepo, pytest-env reads only the first
pytest_envtable above pytest's configuration directory, so a subproject's own table is ignored.✨ With
merge_nested = truein the root table, pytest-env also reads the tables in the directories below it, down to each path given on the command line (or the current directory;testpathsis not read):transform,skip_if_setandunsetkeys.transform = truetemplate applies after the variables it names, whichever table sets them, so a rootDB_URL = { value = "pg://db/{DB_NAME}", transform = true }uses the subproject'sDB_NAME. A cycle between templates is a usage error.env_filesload after the parent's, relative to their own file; like all.envfiles, they don't override table entries.env_files_skip_if_setreplaces the parent's.pytest packages/storage packages/logic, stop with a usage error, since they share one environment.merge_nestedbecomes a reserved key; before, it was exported as a variable. Each entry now records its source file, which--pytest-env-verboseand the "cannot set environment variable" error report.$ pytest packages/storage --pytest-env-verboseCloses #369