diff options
author | Bruno Oliveira <nicoddemus@gmail.com> | 2018-05-21 13:24:39 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-21 13:24:39 -0300 |
commit | 7d0c9837ce4c3411ad8b5d82ee2ce6b1eebeaf28 (patch) | |
tree | 4967c21ce012728d6504029bccec63990246ca6a /testing | |
parent | 4aa7ebaf52ce44760c99f16024c8be6ed8cdd001 (diff) | |
parent | e7f75f69f202a3f980263526d135b76094ad7129 (diff) | |
download | pytest-7d0c9837ce4c3411ad8b5d82ee2ce6b1eebeaf28.tar.gz |
Merge pull request #3459 from RonnyPfannschmidt/mark-iter-name-filter
introduce name filtering for marker iteration again
Diffstat (limited to 'testing')
-rw-r--r-- | testing/test_mark.py | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/testing/test_mark.py b/testing/test_mark.py index 31d3af3e5..764678ab4 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -553,7 +553,6 @@ class TestFunctional(object): self.assert_markers(items, test_foo=('a', 'b'), test_bar=('a',)) @pytest.mark.issue568 - @pytest.mark.xfail(reason="markers smear on methods of base classes") def test_mark_should_not_pass_to_siebling_class(self, testdir): p = testdir.makepyfile(""" import pytest @@ -573,8 +572,16 @@ class TestFunctional(object): """) items, rec = testdir.inline_genitems(p) base_item, sub_item, sub_item_other = items - assert not hasattr(base_item.obj, 'b') - assert not hasattr(sub_item_other.obj, 'b') + print(items, [x.nodeid for x in items]) + # legacy api smears + assert hasattr(base_item.obj, 'b') + assert hasattr(sub_item_other.obj, 'b') + assert hasattr(sub_item.obj, 'b') + + # new api seregates + assert not list(base_item.iter_markers(name='b')) + assert not list(sub_item_other.iter_markers(name='b')) + assert list(sub_item.iter_markers(name='b')) def test_mark_decorator_baseclasses_merged(self, testdir): p = testdir.makepyfile(""" @@ -598,6 +605,26 @@ class TestFunctional(object): self.assert_markers(items, test_foo=('a', 'b', 'c'), test_bar=('a', 'b', 'd')) + def test_mark_closest(self, testdir): + p = testdir.makepyfile(""" + import pytest + + @pytest.mark.c(location="class") + class Test: + @pytest.mark.c(location="function") + def test_has_own(): + pass + + def test_has_inherited(): + pass + + """) + items, rec = testdir.inline_genitems(p) + has_own, has_inherited = items + assert has_own.get_closest_marker('c').kwargs == {'location': 'function'} + assert has_inherited.get_closest_marker('c').kwargs == {'location': 'class'} + assert has_own.get_closest_marker('missing') is None + def test_mark_with_wrong_marker(self, testdir): reprec = testdir.inline_runsource(""" import pytest |