[py-svn] commit/pytest: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Fri Nov 9 12:30:01 CET 2012


2 new commits in pytest:


https://bitbucket.org/hpk42/pytest/changeset/4e85705ea0dc/
changeset:   4e85705ea0dc
user:        hpk42
date:        2012-11-09 12:07:41
summary:     allow to dynamically define markers (e.g. during pytest_collection_modifyitems)
affected #:  5 files

diff -r c6085e0c39c2182f2663e7e969849a279523c1ac -r 4e85705ea0dc4233542fef7f819b315e2376a99d CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,8 @@
 -----------------------------------
 
 - 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
 -----------------------------------


diff -r c6085e0c39c2182f2663e7e969849a279523c1ac -r 4e85705ea0dc4233542fef7f819b315e2376a99d _pytest/__init__.py
--- a/_pytest/__init__.py
+++ b/_pytest/__init__.py
@@ -1,2 +1,2 @@
 #
-__version__ = '2.3.4.dev1'
+__version__ = '2.3.4.dev2'


diff -r c6085e0c39c2182f2663e7e969849a279523c1ac -r 4e85705ea0dc4233542fef7f819b315e2376a99d _pytest/mark.py
--- a/_pytest/mark.py
+++ b/_pytest/mark.py
@@ -73,7 +73,7 @@
         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:


diff -r c6085e0c39c2182f2663e7e969849a279523c1ac -r 4e85705ea0dc4233542fef7f819b315e2376a99d setup.py
--- a/setup.py
+++ b/setup.py
@@ -48,7 +48,7 @@
         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'],


diff -r c6085e0c39c2182f2663e7e969849a279523c1ac -r 4e85705ea0dc4233542fef7f819b315e2376a99d testing/test_mark.py
--- a/testing/test_mark.py
+++ b/testing/test_mark.py
@@ -137,6 +137,30 @@
     assert len(passed) == len(passed_result)
     assert list(passed) == list(passed_result)
 
+ at 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:
 
@@ -386,7 +410,6 @@
         item = dlist[0].items[0]
         assert item.name == "test_one"
 
-
     def test_keyword_extra(self, testdir):
         p = testdir.makepyfile("""
            def test_one():



https://bitbucket.org/hpk42/pytest/changeset/d16cc2de7a1f/
changeset:   d16cc2de7a1f
user:        hpk42
date:        2012-11-09 12:29:33
summary:     allow to pass expressions to "-k" option, just like with the "-m" option
affected #:  5 files

diff -r 4e85705ea0dc4233542fef7f819b315e2376a99d -r d16cc2de7a1fc2363a4abfd4cf46a141227eb5f3 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,8 +2,13 @@
 -----------------------------------
 
 - fix issue91 - add/discuss package/directory level setups in example
-- allow to dynamically define markers/keywords via
-  item.keywords[...]=assignment
+- allow to dynamically define markers via
+  item.keywords[...]=assignment integrating with "-m" option
+- make "-k" accept an expressions the same as with "-m" so that one
+  can write: -k "name1 or name2" etc.  This is a slight incompatibility
+  if you used special syntax like "TestClass.test_method" which you now
+  need to write as -k "TestClass and test_method" to match a certain
+  method in a certain test class.  
 
 Changes between 2.3.2 and 2.3.3
 -----------------------------------


diff -r 4e85705ea0dc4233542fef7f819b315e2376a99d -r d16cc2de7a1fc2363a4abfd4cf46a141227eb5f3 _pytest/__init__.py
--- a/_pytest/__init__.py
+++ b/_pytest/__init__.py
@@ -1,2 +1,2 @@
 #
-__version__ = '2.3.4.dev2'
+__version__ = '2.3.4.dev3'


diff -r 4e85705ea0dc4233542fef7f819b315e2376a99d -r d16cc2de7a1fc2363a4abfd4cf46a141227eb5f3 _pytest/mark.py
--- a/_pytest/mark.py
+++ b/_pytest/mark.py
@@ -51,7 +51,7 @@
     remaining = []
     deselected = []
     for colitem in items:
-        if keywordexpr and skipbykeyword(colitem, keywordexpr):
+        if keywordexpr and not matchkeyword(colitem, keywordexpr):
             deselected.append(colitem)
         else:
             if selectuntil:
@@ -72,37 +72,26 @@
     def __getitem__(self, name):
         return name in self._mydict
 
+class SubstringDict:
+    def __init__(self, mydict):
+        self._mydict = mydict
+    def __getitem__(self, name):
+        for key in self._mydict:
+            if name in key:
+                return True
+        return False
+
 def matchmark(colitem, matchexpr):
     return eval(matchexpr, {}, BoolDict(colitem.keywords))
 
+def matchkeyword(colitem, keywordexpr):
+    keywordexpr = keywordexpr.replace("-", "not ")
+    return eval(keywordexpr, {}, SubstringDict(colitem.keywords))
+
 def pytest_configure(config):
     if config.option.strict:
         pytest.mark._config = config
 
-def skipbykeyword(colitem, keywordexpr):
-    """ return True if they given keyword expression means to
-        skip this collector/item.
-    """
-    if not keywordexpr:
-        return
-
-    itemkeywords = colitem.keywords
-    for key in filter(None, keywordexpr.split()):
-        eor = key[:1] == '-'
-        if eor:
-            key = key[1:]
-        if not (eor ^ matchonekeyword(key, itemkeywords)):
-            return True
-
-def matchonekeyword(key, itemkeywords):
-    for elem in key.split("."):
-        for kw in itemkeywords:
-            if elem in kw:
-                break
-        else:
-            return False
-    return True
-
 class MarkGenerator:
     """ Factory for :class:`MarkDecorator` objects - exposed as
     a ``py.test.mark`` singleton instance.  Example::


diff -r 4e85705ea0dc4233542fef7f819b315e2376a99d -r d16cc2de7a1fc2363a4abfd4cf46a141227eb5f3 setup.py
--- a/setup.py
+++ b/setup.py
@@ -48,7 +48,7 @@
         name='pytest',
         description='py.test: simple powerful testing with Python',
         long_description = long_description,
-        version='2.3.4.dev2',
+        version='2.3.4.dev3',
         url='http://pytest.org',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],


diff -r 4e85705ea0dc4233542fef7f819b315e2376a99d -r d16cc2de7a1fc2363a4abfd4cf46a141227eb5f3 testing/test_mark.py
--- a/testing/test_mark.py
+++ b/testing/test_mark.py
@@ -162,6 +162,24 @@
     assert len(passed) == len(passed_result)
     assert list(passed) == list(passed_result)
 
+ at pytest.mark.multi(spec=[
+        ("interface", ("test_interface",)),
+        ("not interface", ("test_nointer",)),
+])
+def test_keyword_option_custom(spec, testdir):
+    testdir.makepyfile("""
+        def test_interface():
+            pass
+        def test_nointer():
+            pass
+    """)
+    opt, passed_result = spec
+    rec = testdir.inline_run("-k", 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:
 
     def test_mark_per_function(self, testdir):
@@ -366,11 +384,11 @@
         for keyword in ['test_one', 'est_on']:
             #yield check, keyword, 'test_one'
             check(keyword, 'test_one')
-        check('TestClass.test', 'test_method_one')
+        check('TestClass and test', 'test_method_one')
 
     @pytest.mark.parametrize("keyword", [
-        'xxx', 'xxx test_2', 'TestClass', 'xxx -test_1',
-        'TestClass test_2', 'xxx TestClass test_2'])
+        'xxx', 'xxx and test_2', 'TestClass', 'xxx and -test_1',
+        'TestClass and test_2', 'xxx and TestClass and test_2'])
     def test_select_extra_keywords(self, testdir, keyword):
         p = testdir.makepyfile(test_select="""
             def test_1():

Repository URL: https://bitbucket.org/hpk42/pytest/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the pytest-commit mailing list