diff --git a/CHANGELOG b/CHANGELOG index 155f6fffa..a2a129fde 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ Changes between 2.3.5 and 2.4.DEV ----------------------------------- +- fix issue323 - sorting of many module-scoped arg parametrizations + - add support for setUpModule/tearDownModule detection, thanks Brian Okken. - make sessionfinish hooks execute with the same cwd-context as at diff --git a/_pytest/__init__.py b/_pytest/__init__.py index 654c9a59a..0fcc78673 100644 --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.4.0.dev4' +__version__ = '2.4.0.dev5' diff --git a/_pytest/python.py b/_pytest/python.py index 1c2b00bfa..db5d2cca2 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1747,9 +1747,16 @@ def getfuncargnames(function, startindex=None): def parametrize_sorted(items, ignore, cache, scopenum): if scopenum >= 3: return items + + # we pick the first item which has a arg/param combo in the + # requested scope and sort other items with the same combo + # into "newitems" which then is a list of all items using this + # arg/param. + similar_items = [] other_items = [] slicing_argparam = None + slicing_index = 0 for item in items: argparamlist = getfuncargparams(item, ignore, scopenum, cache) if slicing_argparam is None and argparamlist: @@ -1759,7 +1766,8 @@ def parametrize_sorted(items, ignore, cache, scopenum): similar_items.append(item) else: other_items.append(item) - if similar_items: + + if (len(similar_items) + slicing_index) > 1: newignore = ignore.copy() newignore.add(slicing_argparam) part2 = parametrize_sorted( diff --git a/setup.py b/setup.py index d8b32746b..c5e7890f7 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def main(): name='pytest', description='py.test: simple powerful testing with Python', long_description = long_description, - version='2.4.0.dev4', + version='2.4.0.dev5', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 71438870a..75e3aa461 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -555,6 +555,20 @@ class TestMetafuncFunctional: reprec = testdir.inline_run() reprec.assertoutcome(passed=5) + def test_parametrize_issue323(self, testdir): + testdir.makepyfile(""" + import pytest + + @pytest.fixture(scope='module', params=range(966)) + def foo(request): + return request.param + + def test_it(foo): + pass + """) + reprec = testdir.inline_run("--collectonly") + assert not reprec.getcalls("pytest_internalerror") + def test_usefixtures_seen_in_generate_tests(self, testdir): testdir.makepyfile(""" import pytest diff --git a/tox.ini b/tox.ini index 3af69e880..16e2c12d7 100644 --- a/tox.ini +++ b/tox.ini @@ -98,4 +98,4 @@ python_files=test_*.py *_test.py testing/*/*.py python_classes=Test Acceptance python_functions=test pep8ignore = E401 E225 E261 E128 E124 E302 -norecursedirs = .tox ja +norecursedirs = .tox ja .hg