From ec02f694ef2b1ece4fbaf57989ad727d8f4ebcb2 Mon Sep 17 00:00:00 2001 From: aselus-hub Date: Wed, 9 Dec 2015 11:32:19 -0800 Subject: [PATCH 1/8] Update python.py updated dictionary itteration to create a list for generation, so that tests can be added in the generator functions under python3. This works fine as-is in python2 because python 2 already creates a list, whereas python3 returns an itterator. Forcing a list format for the return fixes python3 to work the same way as python2 --- _pytest/python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/python.py b/_pytest/python.py index 4ff3f4fc0..926f503be 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -451,7 +451,7 @@ class PyCollector(PyobjMixin, pytest.Collector): seen = {} l = [] for dic in dicts: - for name, obj in dic.items(): + for name, obj in list(dic.items()): if name in seen: continue seen[name] = True From dfaeefd69207b4e8b0e5d2e24b037a3d49a3e4e5 Mon Sep 17 00:00:00 2001 From: aselus-hub Date: Thu, 10 Dec 2015 14:45:36 -0800 Subject: [PATCH 2/8] added test to verify injection. --- testing/python/collect.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/testing/python/collect.py b/testing/python/collect.py index 1a85faf9c..0dd9ef1da 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -1076,3 +1076,19 @@ def test_dont_collect_non_function_callable(testdir): 'WC2 *', '*1 passed, 1 pytest-warnings in *', ]) + + +def test_class_injection_does_not_break_collection(testdir): + testdir.makeconftest(""" + from test_inject import TestClass + def pytest_generate_tests(metafunc): + TestClass.changed_var = {} + """) + testdir.makepyfile(test_inject=''' + class TestClass(object): + def test_injection(self): + """Test being parametrized.""" + pass + ''') + result = testdir.runpytest() + assert "RuntimeError: dictionary changed size during iteration" not in result.stdout.str() \ No newline at end of file From af54e097590d3d24550e6dd0bb62fa0113aa6339 Mon Sep 17 00:00:00 2001 From: aselus-hub Date: Thu, 10 Dec 2015 14:46:51 -0800 Subject: [PATCH 3/8] nit: fixed newline --- testing/python/collect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/python/collect.py b/testing/python/collect.py index 0dd9ef1da..eb0a399bd 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -1091,4 +1091,4 @@ def test_class_injection_does_not_break_collection(testdir): pass ''') result = testdir.runpytest() - assert "RuntimeError: dictionary changed size during iteration" not in result.stdout.str() \ No newline at end of file + assert "RuntimeError: dictionary changed size during iteration" not in result.stdout.str() From 34db8aed341418af52de742f83503bf0f948c6c5 Mon Sep 17 00:00:00 2001 From: aselus-hub Date: Thu, 10 Dec 2015 15:02:57 -0800 Subject: [PATCH 4/8] added verification that test actually passed. --- testing/python/collect.py | 1 + 1 file changed, 1 insertion(+) diff --git a/testing/python/collect.py b/testing/python/collect.py index eb0a399bd..34bf5d810 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -1092,3 +1092,4 @@ def test_class_injection_does_not_break_collection(testdir): ''') result = testdir.runpytest() assert "RuntimeError: dictionary changed size during iteration" not in result.stdout.str() + result.stdout.fnmatch_lines(['*== 1 passed in *']) From 74f7efd2a34e9dbbbccaeb21f93bd51fa234ab68 Mon Sep 17 00:00:00 2001 From: aselus-hub Date: Thu, 10 Dec 2015 15:10:55 -0800 Subject: [PATCH 5/8] added line comparison that is pytest-sugar agnostic. --- testing/python/collect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/python/collect.py b/testing/python/collect.py index 34bf5d810..89b902fc9 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -1092,4 +1092,4 @@ def test_class_injection_does_not_break_collection(testdir): ''') result = testdir.runpytest() assert "RuntimeError: dictionary changed size during iteration" not in result.stdout.str() - result.stdout.fnmatch_lines(['*== 1 passed in *']) + result.stdout.fnmatch_lines(['*1 passed*']) From 2b2240e90496dbe04a59eb913125b08efa840c08 Mon Sep 17 00:00:00 2001 From: aselus-hub Date: Thu, 10 Dec 2015 15:15:09 -0800 Subject: [PATCH 6/8] added myself to authors, added changelog entry. --- AUTHORS | 1 + CHANGELOG | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/AUTHORS b/AUTHORS index 641e20441..7206125c8 100644 --- a/AUTHORS +++ b/AUTHORS @@ -71,3 +71,4 @@ Eric Hunsberger Simon Gomizelj Russel Winder Ben Webb +Alexei Kozlenok diff --git a/CHANGELOG b/CHANGELOG index d1ac12a52..5232e7204 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,10 @@ 2.8.5.dev0 ---------- +- fix #1243: fixed injection to class breaking collection step, by replacing + generated interation with list traversal, added test to verify in python/collect.py + Thanks Ronny Pfannschmidt and Nicoddemus for the PR + - fix #1074: precompute junitxml chunks instead of storing the whole tree in objects Thanks Bruno Oliveira for the report and Ronny Pfannschmidt for the PR From 1216a27b44a2eeaae8f02dd2675596581d57246c Mon Sep 17 00:00:00 2001 From: aselus-hub Date: Thu, 10 Dec 2015 15:19:08 -0800 Subject: [PATCH 7/8] added docstrign to inection collection test. --- testing/python/collect.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/testing/python/collect.py b/testing/python/collect.py index 89b902fc9..bebc13318 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -1079,6 +1079,12 @@ def test_dont_collect_non_function_callable(testdir): def test_class_injection_does_not_break_collection(testdir): + """Tests whether injection during collection time will terminate testing. + + In this case the error should not occur if the TestClass itself + is modified during collection time, and the original method list + is still used for collection. + """ testdir.makeconftest(""" from test_inject import TestClass def pytest_generate_tests(metafunc): From ad05cbe6da758331026797c3886146448c3e5e1c Mon Sep 17 00:00:00 2001 From: aselus-hub Date: Thu, 10 Dec 2015 15:39:31 -0800 Subject: [PATCH 8/8] fixed meesage. --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 5232e7204..499660fa6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,7 +3,7 @@ - fix #1243: fixed injection to class breaking collection step, by replacing generated interation with list traversal, added test to verify in python/collect.py - Thanks Ronny Pfannschmidt and Nicoddemus for the PR + PR by Alexei Kozlenok, Thanks Ronny Pfannschmidt and Nicoddemus for the review and help. - fix #1074: precompute junitxml chunks instead of storing the whole tree in objects Thanks Bruno Oliveira for the report and Ronny Pfannschmidt for the PR