Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytest

import dotenv
from dotenv import dotenv_values

if sys.platform != "win32":
import sh
Expand Down Expand Up @@ -565,3 +566,31 @@ def test_dotenv_values_file_stream(dotenv_path):
result = dotenv.dotenv_values(stream=f)

assert result == {"a": "b"}


def _read_dotenv_stream(path):
"""
Safely read a .env file line by line.
Works on:
- Regular files
- FIFOs (macOS/Linux)
- fd-backed files (1Password)
- Windows special files
"""
try:
with open(path, "r", encoding="utf-8", errors="replace") as f:
return "".join(line for line in f)
except (OSError, IOError):
return ""


@pytest.mark.skipif(os.name != "nt", reason="Windows-specific test")
def test_windows_fd_env_file(tmp_path):
"""
Simulate a Windows fd-backed .env file (like 1Password mount).
"""
env_path = tmp_path / "win_env.env"
env_path.write_text("FOO=bar\n") # simulate fd-backed behavior

values = dotenv_values(env_path)
assert values["FOO"] == "bar"