Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cached_setup and Metafunc.addcall #4490

Merged

Conversation

nicoddemus
Copy link
Member

Removed request.cached_setup and Metafunc.addcall.

Fix #4489, #3083

A note: I had to remove some tests because Metafunc.addcall can combine arguments in multiple levels of pytest_generate_tests hooks, while Metafunc.parametrize specifically has a check against that. For example:

    def test_generate_plugin_and_module(self, testdir):
        testdir.makeconftest(
            """
            def pytest_generate_tests(metafunc):
                assert "arg1" in metafunc.fixturenames
                metafunc.addcall(id="world", param=(2,100))
        """
        )
        p = testdir.makepyfile(
            """
            def pytest_generate_tests(metafunc):
                metafunc.addcall(param=(1,1), id="hello")

            import pytest
            @pytest.fixture
            def arg1(request):
                return request.param[0]
            @pytest.fixture
            def arg2(request):
                return request.param[1]

            class TestClass(object):
                def test_myfunc(self, arg1, arg2):
                    assert arg1 == arg2
        """
        )
        result = testdir.runpytest("-v", p, SHOW_PYTEST_WARNINGS_ARG)
        result.stdout.fnmatch_lines(
            [
                "*test_myfunc*hello*PASS*",
                "*test_myfunc*world*FAIL*",
                "*1 failed, 1 passed*",
            ]
        )

When converted to use metafunc.parametrize:

    def test_generate_plugin_and_module(self, testdir):
        testdir.makeconftest(
            """
            def pytest_generate_tests(metafunc):
                assert "arg1" in metafunc.fixturenames
                metafunc.parametrize('arg1, arg2', [(2, 100)], ids=["world"])
        """
        )
        p = testdir.makepyfile(
            """
            def pytest_generate_tests(metafunc):
                metafunc.parametrize('arg1, arg2', [(1, 1)], ids=["hello"])    

            class TestClass(object):
                def test_myfunc(self, arg1, arg2):
                    assert arg1 == arg2
        """
        )
        result = testdir.runpytest("-v", p, SHOW_PYTEST_WARNINGS_ARG)
        result.stdout.fnmatch_lines(
            [
                "*test_myfunc*hello*PASS*",
                "*test_myfunc*world*FAIL*",
                "*1 failed, 1 passed*",
            ]
        )

We get this error:

ValueError: duplicate 'arg1'

I think this is fine, as users who might still rely on cached_setup's behavior would have probably complain by now.

Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty clean break! nice!

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good, we ought to investigate which of the changed tests are better removed - i beleive 2-3 of them might be better gone

@codecov
Copy link

codecov bot commented Dec 1, 2018

Codecov Report

Merging #4490 into features will decrease coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##           features    #4490      +/-   ##
============================================
- Coverage     95.82%   95.76%   -0.06%     
============================================
  Files           111      111              
  Lines         25038    24853     -185     
  Branches       2463     2455       -8     
============================================
- Hits          23992    23801     -191     
- Misses          736      741       +5     
- Partials        310      311       +1
Flag Coverage Δ
#docs 29.36% <100%> (+0.12%) ⬆️
#doctesting 29.36% <100%> (+0.12%) ⬆️
#linting 29.36% <100%> (+0.12%) ⬆️
#linux 95.59% <100%> (-0.06%) ⬇️
#nobyte 92.47% <100%> (-0.08%) ⬇️
#numpy 93.2% <100%> (-0.11%) ⬇️
#pexpect 41.71% <100%> (+0.05%) ⬆️
#py27 93.81% <100%> (-0.07%) ⬇️
#py34 91.98% <100%> (-0.02%) ⬇️
#py35 92% <100%> (-0.02%) ⬇️
#py36 92.02% <100%> (-0.02%) ⬇️
#py37 93.95% <100%> (-0.05%) ⬇️
#trial 93.2% <100%> (-0.11%) ⬇️
#windows 94.01% <100%> (-0.07%) ⬇️
#xdist 93.85% <100%> (-0.08%) ⬇️
Impacted Files Coverage Δ
src/_pytest/python.py 93.05% <ø> (-1.55%) ⬇️
testing/python/metafunc.py 95.77% <ø> (+0.41%) ⬆️
testing/deprecated_test.py 100% <ø> (ø) ⬆️
src/_pytest/deprecated.py 100% <ø> (ø) ⬆️
testing/acceptance_test.py 98.28% <ø> (ø) ⬆️
testing/python/fixture.py 99.19% <100%> (-0.05%) ⬇️
src/_pytest/fixtures.py 97.18% <100%> (-0.21%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 06dc6e3...40b85d7. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Dec 1, 2018

Codecov Report

Merging #4490 into features will decrease coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##           features    #4490      +/-   ##
============================================
- Coverage     95.82%   95.76%   -0.06%     
============================================
  Files           111      111              
  Lines         25038    24853     -185     
  Branches       2463     2455       -8     
============================================
- Hits          23992    23801     -191     
- Misses          736      741       +5     
- Partials        310      311       +1
Flag Coverage Δ
#docs 29.36% <100%> (+0.12%) ⬆️
#doctesting 29.36% <100%> (+0.12%) ⬆️
#linting 29.36% <100%> (+0.12%) ⬆️
#linux 95.59% <100%> (-0.06%) ⬇️
#nobyte 92.47% <100%> (-0.08%) ⬇️
#numpy 93.2% <100%> (-0.11%) ⬇️
#pexpect 41.71% <100%> (+0.05%) ⬆️
#py27 93.81% <100%> (-0.07%) ⬇️
#py34 91.98% <100%> (-0.02%) ⬇️
#py35 92% <100%> (-0.02%) ⬇️
#py36 92.02% <100%> (-0.02%) ⬇️
#py37 93.95% <100%> (-0.05%) ⬇️
#trial 93.2% <100%> (-0.11%) ⬇️
#windows 94.01% <100%> (-0.07%) ⬇️
#xdist 93.85% <100%> (-0.08%) ⬇️
Impacted Files Coverage Δ
src/_pytest/python.py 93.05% <ø> (-1.55%) ⬇️
testing/python/metafunc.py 95.77% <ø> (+0.41%) ⬆️
testing/deprecated_test.py 100% <ø> (ø) ⬆️
src/_pytest/deprecated.py 100% <ø> (ø) ⬆️
testing/acceptance_test.py 98.28% <ø> (ø) ⬆️
testing/python/fixture.py 99.19% <100%> (-0.05%) ⬇️
src/_pytest/fixtures.py 97.18% <100%> (-0.21%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 06dc6e3...40b85d7. Read the comment docs.

@nicoddemus nicoddemus merged commit a131f0a into pytest-dev:features Dec 1, 2018
@nicoddemus nicoddemus deleted the remove-cached-setup-add-call branch December 1, 2018 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants