diff --git a/conftest.py b/conftest.py index b2065532..425740dd 100644 --- a/conftest.py +++ b/conftest.py @@ -1,4 +1,25 @@ +import pytest + +import cssutils + + collect_ignore = [ 'cssutils/_fetchgae.py', 'tools', ] + + +@pytest.fixture(autouse=True) +def hermetic_profiles(): + """ + Ensure that tests are hermetic w.r.t. profiles. + """ + before = list(cssutils.profile.profiles) + yield + assert before == cssutils.profile.profiles + + +@pytest.fixture +def saved_profiles(monkeypatch): + profiles = cssutils.profiles.Profiles(log=cssutils.log) + monkeypatch.setattr(cssutils, 'profile', profiles) diff --git a/cssutils/tests/test_profiles.py b/cssutils/tests/test_profiles.py index c9976c59..1348bc00 100644 --- a/cssutils/tests/test_profiles.py +++ b/cssutils/tests/test_profiles.py @@ -78,6 +78,7 @@ def check(*results): # restore cssutils.profile = saved + @pytest.mark.usefixtures('saved_profiles') def test_addProfile(self): "Profiles.addProfile with custom validation function" # unknown profile diff --git a/examples/website.py b/examples/website.py index f41c1618..0c74d1be 100644 --- a/examples/website.py +++ b/examples/website.py @@ -11,8 +11,7 @@ def profile(): """ >>> sheet = cssutils.parseString('x { -test-custommacro: x }') - The following fails in a full suite test run due to non-hermetic tests. - >>> print(sheet.cssRules[0].style.getProperties()[0].valid) # doctest: +SKIP + >>> print(sheet.cssRules[0].style.getProperties()[0].valid) False >>> M1 = { ... 'testvalue': 'x' @@ -24,6 +23,7 @@ def profile(): ... # custom validation function ... '-test-funcval': lambda v: int(v) > 0 ... } + >>> profiles = getfixture('saved_profiles') # keep test hermetic >>> cssutils.profile.addProfile('test', P1, M1) >>> sheet = cssutils.parseString('x { -test-custommacro: x }') >>> print(sheet.cssRules[0].style.getProperties()[0].valid)