[Pytest-commit] commit/pytest: hpk42: simplify the implementation of NodeKeywords getting rid of __ descriptors appearing there.
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Thu Oct 3 13:53:30 CEST 2013
1 new commit in pytest:
https://bitbucket.org/hpk42/pytest/commits/0e4482f0ba67/
Changeset: 0e4482f0ba67
User: hpk42
Date: 2013-10-03 13:53:22
Summary: simplify the implementation of NodeKeywords getting rid of __ descriptors appearing there.
Affected #: 4 files
diff -r 6ce6602773ace1949b47d09c7bcff384530dbfb5 -r 0e4482f0ba672ae3e31d21cd12d5f06b15e621d7 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,10 @@
Changes between 2.4.1 and 2.4.2
-----------------------------------
+- fix "-k" matching of tests where "repr" and "attr" and other names would
+ cause wrong matches because of an internal implementation quirk
+ (don't ask) which is now properly implemented. fixes issue345.
+
- avoid "IOError: Bad Filedescriptor" on pytest shutdown by not closing
the internal dupped stdout (fix is slightly hand-wavy but work).
diff -r 6ce6602773ace1949b47d09c7bcff384530dbfb5 -r 0e4482f0ba672ae3e31d21cd12d5f06b15e621d7 _pytest/main.py
--- a/_pytest/main.py
+++ b/_pytest/main.py
@@ -170,30 +170,39 @@
class NodeKeywords(MappingMixin):
def __init__(self, node):
- parent = node.parent
- bases = parent and (parent.keywords._markers,) or ()
- self._markers = type("dynmarker", bases, {node.name: True})
+ self.node = node
+ self.parent = node.parent
+ self._markers = {node.name: True}
def __getitem__(self, key):
try:
- return getattr(self._markers, key)
- except AttributeError:
- raise KeyError(key)
+ return self._markers[key]
+ except KeyError:
+ if self.parent is None:
+ raise
+ return self.parent.keywords[key]
def __setitem__(self, key, value):
- setattr(self._markers, key, value)
+ self._markers[key] = value
def __delitem__(self, key):
- delattr(self._markers, key)
+ raise ValueError("cannot delete key in keywords dict")
def __iter__(self):
- return iter(self.keys())
+ seen = set(self._markers)
+ if self.parent is not None:
+ seen.update(self.parent.keywords)
+ return iter(seen)
def __len__(self):
- return len(self.keys())
+ return len(self.__iter__())
def keys(self):
- return dir(self._markers)
+ return list(self)
+
+ def __repr__(self):
+ return "<NodeKeywords for node %s>" % (self.node, )
+
class Node(object):
""" base class for Collector and Item the test collection tree.
diff -r 6ce6602773ace1949b47d09c7bcff384530dbfb5 -r 0e4482f0ba672ae3e31d21cd12d5f06b15e621d7 bench/bench.py
--- a/bench/bench.py
+++ b/bench/bench.py
@@ -7,4 +7,4 @@
p = pstats.Stats("prof")
p.strip_dirs()
p.sort_stats('cumulative')
- print(p.print_stats(30))
+ print(p.print_stats(50))
diff -r 6ce6602773ace1949b47d09c7bcff384530dbfb5 -r 0e4482f0ba672ae3e31d21cd12d5f06b15e621d7 testing/test_collection.py
--- a/testing/test_collection.py
+++ b/testing/test_collection.py
@@ -566,4 +566,25 @@
])
+class TestNodekeywords:
+ def test_no_under(self, testdir):
+ modcol = testdir.getmodulecol("""
+ def test_pass(): pass
+ def test_fail(): assert 0
+ """)
+ l = list(modcol.keywords)
+ assert modcol.name in l
+ for x in l:
+ assert not x.startswith("_")
+ assert modcol.name in repr(modcol.keywords)
+ def test_issue345(self, testdir):
+ testdir.makepyfile("""
+ def test_should_not_be_selected():
+ assert False, 'I should not have been selected to run'
+
+ def test___repr__():
+ pass
+ """)
+ reprec = testdir.inline_run("-k repr")
+ reprec.assertoutcome(passed=1, failed=0)
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