update env file precedence

This commit is contained in:
David Lord 2024-11-07 11:27:51 -08:00
parent ce08bc704e
commit 2c31603042
No known key found for this signature in database
GPG key ID: 43368A7AA8CC5926
3 changed files with 90 additions and 47 deletions

View file

@ -398,7 +398,12 @@ def test_flaskgroup_nested(app, runner):
def test_no_command_echo_loading_error():
from flask.cli import cli
runner = CliRunner(mix_stderr=False)
try:
runner = CliRunner(mix_stderr=False)
except (DeprecationWarning, TypeError):
# Click >= 8.2
runner = CliRunner()
result = runner.invoke(cli, ["missing"])
assert result.exit_code == 2
assert "FLASK_APP" in result.stderr
@ -408,7 +413,12 @@ def test_no_command_echo_loading_error():
def test_help_echo_loading_error():
from flask.cli import cli
runner = CliRunner(mix_stderr=False)
try:
runner = CliRunner(mix_stderr=False)
except (DeprecationWarning, TypeError):
# Click >= 8.2
runner = CliRunner()
result = runner.invoke(cli, ["--help"])
assert result.exit_code == 0
assert "FLASK_APP" in result.stderr
@ -420,7 +430,13 @@ def test_help_echo_exception():
raise Exception("oh no")
cli = FlaskGroup(create_app=create_app)
runner = CliRunner(mix_stderr=False)
try:
runner = CliRunner(mix_stderr=False)
except (DeprecationWarning, TypeError):
# Click >= 8.2
runner = CliRunner()
result = runner.invoke(cli, ["--help"])
assert result.exit_code == 0
assert "Exception: oh no" in result.stderr
@ -537,7 +553,7 @@ def test_load_dotenv(monkeypatch):
# test env file encoding
assert os.environ["HAM"] == "火腿"
# Non existent file should not load
assert not load_dotenv("non-existent-file")
assert not load_dotenv("non-existent-file", load_defaults=False)
@need_dotenv