Commits

holger krekel committed 4e85705

allow to dynamically define markers (e.g. during pytest_collection_modifyitems)

  • Participants
  • Parent commits c6085e0

Comments (0)

Files changed (5)

 -----------------------------------
 
 - fix issue91 - add/discuss package/directory level setups in example
+- allow to dynamically define markers/keywords via
+  item.keywords[...]=assignment
 
 Changes between 2.3.2 and 2.3.3
 -----------------------------------

File _pytest/__init__.py

 #
-__version__ = '2.3.4.dev1'
+__version__ = '2.3.4.dev2'

File _pytest/mark.py

         return name in self._mydict
 
 def matchmark(colitem, matchexpr):
-    return eval(matchexpr, {}, BoolDict(colitem.obj.__dict__))
+    return eval(matchexpr, {}, BoolDict(colitem.keywords))
 
 def pytest_configure(config):
     if config.option.strict:
         name='pytest',
         description='py.test: simple powerful testing with Python',
         long_description = long_description,
-        version='2.3.4.dev1',
+        version='2.3.4.dev2',
         url='http://pytest.org',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

File testing/test_mark.py

     assert len(passed) == len(passed_result)
     assert list(passed) == list(passed_result)
 
+@pytest.mark.multi(spec=[
+        ("interface", ("test_interface",)),
+        ("not interface", ("test_nointer",)),
+])
+def test_mark_option_custom(spec, testdir):
+    testdir.makeconftest("""
+        import pytest
+        def pytest_collection_modifyitems(items):
+            for item in items:
+                if "interface" in item.nodeid:
+                    item.keywords["interface"] = pytest.mark.interface
+    """)
+    testdir.makepyfile("""
+        def test_interface():
+            pass
+        def test_nointer():
+            pass
+    """)
+    opt, passed_result = spec
+    rec = testdir.inline_run("-m", opt)
+    passed, skipped, fail = rec.listoutcomes()
+    passed = [x.nodeid.split("::")[-1] for x in passed]
+    assert len(passed) == len(passed_result)
+    assert list(passed) == list(passed_result)
 
 class TestFunctional:
 
         item = dlist[0].items[0]
         assert item.name == "test_one"
 
-
     def test_keyword_extra(self, testdir):
         p = testdir.makepyfile("""
            def test_one():