From 439211082a96ddb7387e0e0c2dbf5e26ad7b2654 Mon Sep 17 00:00:00 2001 From: Greg Back Date: Wed, 18 Jan 2017 16:14:57 -0800 Subject: [PATCH] Add custom clock fixture --- stix2/test/test_stix2.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/stix2/test/test_stix2.py b/stix2/test/test_stix2.py index 82a7607..b96dfb4 100644 --- a/stix2/test/test_stix2.py +++ b/stix2/test/test_stix2.py @@ -9,6 +9,19 @@ import stix2 amsterdam = pytz.timezone('Europe/Amsterdam') eastern = pytz.timezone('US/Eastern') +FAKE_TIME = datetime.datetime(2017, 01, 01, 12, 34, 56) + + +# Inspired by: http://stackoverflow.com/a/24006251 +@pytest.fixture +def clock(monkeypatch): + + class mydatetime(datetime.datetime): + @classmethod + def now(cls): + return FAKE_TIME + + monkeypatch.setattr(datetime, 'datetime', mydatetime) @pytest.mark.parametrize('dt,timestamp', [