diff --git a/python/tests/conftest.py b/python/tests/conftest.py index 87aa9a363..a6f6e62ad 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -1,11 +1,29 @@ from pathlib import Path +import datetime + import numpy as np - import pytest +from _pytest.monkeypatch import MonkeyPatch -# Use to monkeypatch damask.version (for comparsion to reference files that contain version information) -def pytest_configure(): - pytest.dummy_version = '99.99.99-9999-pytest' +import damask + + +patched_version = '99.99.99-9999-pytest' +@pytest.fixture +def patch_damask_version(monkeysession): + """Set damask.version for reproducible tests results.""" + monkeysession.setattr(damask, 'version', patched_version) + +patched_date = datetime.datetime(2019, 11, 2, 11, 58, 0) +@pytest.fixture +def patch_datetime_now(monkeysession): + """Set datetime.datetime.now for reproducible tests results.""" + class mydatetime: + @classmethod + def now(cls): + return patched_date + + monkeysession.setattr(datetime, 'datetime', mydatetime) def pytest_addoption(parser): diff --git a/python/tests/test_Colormap.py b/python/tests/test_Colormap.py index b3309f12b..4fe0cc9fb 100644 --- a/python/tests/test_Colormap.py +++ b/python/tests/test_Colormap.py @@ -17,6 +17,10 @@ def reference_dir(reference_dir_base): class TestColormap: + @pytest.fixture(autouse=True) + def _patch_damask_version(self, patch_damask_version): + print('patched damask.version') + def test_conversion(self): specials = np.array([[0.,0.,0.], @@ -29,7 +33,6 @@ class TestColormap: [1.,1.,1.] ]) rgbs = np.vstack((specials,np.random.rand(100,3))) - pass # class not integrated for rgb in rgbs: print('rgb',rgb) @@ -150,8 +153,7 @@ class TestColormap: ('GOM','.legend'), ('Gmsh','.msh') ]) - def test_compare_reference(self,format,ext,tmpdir,reference_dir,update,monkeypatch): - monkeypatch.setattr(damask, 'version', pytest.dummy_version) + def test_compare_reference(self,format,ext,tmpdir,reference_dir,update): name = 'binary' c = Colormap.from_predefined(name) if update: