From f27ff9c492e8588be6d210dcaf3374b04b654cde Mon Sep 17 00:00:00 2001 From: Anubhav Date: Sun, 22 Nov 2026 14:41:40 +0530 Subject: [PATCH] Read STRICT from command-line environment variables --- email_validator/__main__.py | 2 +- tests/test_main.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/email_validator/__main__.py b/email_validator/__main__.py index 1d0d779..d072f27 100644 --- a/email_validator/__main__.py +++ b/email_validator/__main__.py @@ -30,7 +30,7 @@ def main(dns_resolver: Optional[_Resolver] = None) -> None: # Set options from environment variables. options: dict[str, Any] = {} for varname in ('ALLOW_SMTPUTF8', 'ALLOW_EMPTY_LOCAL', 'ALLOW_QUOTED_LOCAL', 'ALLOW_DOMAIN_LITERAL', - 'ALLOW_DISPLAY_NAME', + 'ALLOW_DISPLAY_NAME', 'STRICT', 'GLOBALLY_DELIVERABLE', 'CHECK_DELIVERABILITY', 'TEST_ENVIRONMENT'): if varname in os.environ: # bool() would make any non-empty string True, so e.g. diff --git a/tests/test_main.py b/tests/test_main.py index 5bc7d91..408ed65 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -104,6 +104,16 @@ def test_main_falsy_test_environment_from_env(monkeypatch: pytest.MonkeyPatch, c assert stdout == 'The part after the @-sign is a special-use or reserved name that cannot be used with email.\n' +@pytest.mark.parametrize('value', ['true', '1']) +def test_main_strict_from_env(monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], value: str) -> None: + monkeypatch.setenv('STRICT', value) + monkeypatch.setenv('CHECK_DELIVERABILITY', 'false') + monkeypatch.setattr('sys.argv', ['email_validator', 'a' * 65 + '@example.com']) + validator_command_line_tool(dns_resolver=RESOLVER) + stdout, _ = capsys.readouterr() + assert stdout == 'The email address is too long before the @-sign (1 character too many).\n' + + def test_main_default_timeout_from_env(monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None: import json import email_validator