Skip to content

Commit d50ccce

Browse files
committed
tests: freeze date for fact tests
This fixes tests like `ls` parsing which use the current year as the CLI doesn't include it.
1 parent 9efcb40 commit d50ccce

File tree

3 files changed

+28
-49
lines changed

3 files changed

+28
-49
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ dev = [
7878
"ipdbplugin",
7979
# dev-only lint extras
8080
"typos>=1.36.2",
81-
"redbaron",
81+
"freezegun>=1.5.5",
8282
]
8383

8484
[project.scripts]

tests/test_facts.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from os import listdir, path
55
from unittest import TestCase
66

7+
from freezegun import freeze_time
78
from testgen import TestGenerator
89

910
from pyinfra.api import StringCommand
@@ -89,7 +90,8 @@ def _test_fn(self, test_name, test_data, fact):
8990
if isinstance(command_output, str):
9091
command_output = command_output.splitlines()
9192

92-
data = fact.process(command_output)
93+
# Freeze the date so any facts that use the "current" year will used 2025
94+
data = freeze_time("2025-01-01")(fact.process)(command_output)
9395
if short_fact:
9496
data = short_fact.process_data(data)
9597

0 commit comments

Comments
 (0)