From 41cef6f5f2a20b918bb9b9204ca6c91b47442d15 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sat, 8 Aug 2015 02:09:08 +0200 Subject: [PATCH 1/3] Don't skip fixtures that are substrings of params Bug introduced with https://bitbucket.org/pytest-dev/pytest/pull-requests/257/allow-to-override-parametrized-fixtures Fix #736 --- _pytest/python.py | 2 +- testing/python/collect.py | 12 +++++++++++- testing/python/fixture.py | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/_pytest/python.py b/_pytest/python.py index 8438ca428c3..88c7d1a39d8 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1818,7 +1818,7 @@ def pytest_generate_tests(self, metafunc): if fixturedef.params is not None: func_params = getattr(getattr(metafunc.function, 'parametrize', None), 'args', [[None]]) # skip directly parametrized arguments - if argname not in func_params and argname not in func_params[0]: + if argname not in func_params: metafunc.parametrize(argname, fixturedef.params, indirect=True, scope=fixturedef.scope, ids=fixturedef.ids) diff --git a/testing/python/collect.py b/testing/python/collect.py index 97250028a84..029b0b69326 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -412,9 +412,19 @@ def value(): ['overridden']) def test_overridden_via_param(value): assert value == 'overridden' + + @pytest.mark.parametrize('somevalue', ['overridden']) + def test_not_overridden(value, somevalue): + assert value == 'value' + assert somevalue == 'overridden' + + @pytest.mark.parametrize('other,value', [('foo', 'overridden')]) + def test_overridden_via_multiparam(other, value): + assert other == 'foo' + assert value == 'overridden' """) rec = testdir.inline_run() - rec.assertoutcome(passed=1) + rec.assertoutcome(passed=3) def test_parametrize_overrides_parametrized_fixture(self, testdir): diff --git a/testing/python/fixture.py b/testing/python/fixture.py index 8bf738c5d8f..48f52d2a04a 100644 --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -1598,6 +1598,22 @@ def test_result(): reprec = testdir.inline_run() reprec.assertoutcome(passed=4) + def test_multiple_parametrization_issue_736(self, testdir): + testdir.makepyfile(""" + import pytest + + @pytest.fixture(params=[1,2,3]) + def foo(request): + return request.param + + @pytest.mark.parametrize('foobar', [4,5,6]) + def test_issue(foo, foobar): + assert foo in [1,2,3] + assert foobar in [4,5,6] + """) + reprec = testdir.inline_run() + reprec.assertoutcome(passed=9) + def test_scope_session(self, testdir): testdir.makepyfile(""" import pytest From cafd71eb290f39bac05c8c9e504953a3f1ddfd72 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sat, 8 Aug 2015 03:05:15 +0200 Subject: [PATCH 2/3] Update changelog for #926 Also fix some inconsistencies in the changelog on the way. --- CHANGELOG | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cec72c229f8..6c9c1adbc2a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,10 @@ - Fix #562: @nose.tools.istest now fully respected. +- Fix issue736: Fix a bug where fixture params would be discarded when combined + with parametrization markers. + Thanks to Markus Unterwaditzer for the PR. + - parametrize now also generates meaningful test IDs for enum, regex and class objects (as opposed to class instances). Thanks to Florian Bruhin for the PR. @@ -10,7 +14,7 @@ - Add 'warns' to assert that warnings are thrown (like 'raises'). Thanks to Eric Hunsberger for the PR. -- Fix #683: Do not apply an already applied mark. Thanks ojake for the PR. +- Fix issue683: Do not apply an already applied mark. Thanks ojake for the PR. - Deal with capturing failures better so fewer exceptions get lost to /dev/null. Thanks David Szotten for the PR. @@ -36,7 +40,7 @@ deprecated. Thanks Bruno Oliveira for the PR. -- fix issue 808: pytest's internal assertion rewrite hook now implements the +- fix issue808: pytest's internal assertion rewrite hook now implements the optional PEP302 get_data API so tests can access data files next to them. Thanks xmo-odoo for request and example and Bruno Oliveira for the PR. From 1d5215ab4f2323c225e6a8d1890f138aef518c9f Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sat, 8 Aug 2015 03:24:30 +0200 Subject: [PATCH 3/3] Add myself to authors --- AUTHORS | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index b0073c54fcc..2fdc39fc2fd 100644 --- a/AUTHORS +++ b/AUTHORS @@ -25,11 +25,11 @@ Daniel Grana Daniel Nuri Dave Hunt David Mohr +Edison Gustavo Muenz Eduardo Schettino +Eric Hunsberger Eric Siegerman Florian Bruhin -Edison Gustavo Muenz -Eric Hunsberger Floris Bruynooghe Graham Horler Grig Gheorghiu @@ -47,6 +47,7 @@ Maciek Fijalkowski Maho Marc Schlaich Mark Abramowitz +Markus Unterwaditzer Martijn Faassen Nicolas Delaby Pieter Mulder