1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
import os
import pathlib
import sys
import threading
import pytest
from dotenv import load_dotenv
pytestmark = pytest.mark.skipif(
sys.platform.startswith("win"), reason="FIFOs are Unix-only"
)
def test_load_dotenv_from_fifo(tmp_path: pathlib.Path, monkeypatch):
fifo = tmp_path / ".env"
os.mkfifo(fifo) # create named pipe
def writer():
with open(fifo, "w", encoding="utf-8") as w:
w.write("MY_PASSWORD=pipe-secret\n")
t = threading.Thread(target=writer)
t.start()
# Ensure env is clean
monkeypatch.delenv("MY_PASSWORD", raising=False)
ok = load_dotenv(dotenv_path=str(fifo), override=True)
t.join(timeout=2)
assert ok is True
assert os.getenv("MY_PASSWORD") == "pipe-secret"
|