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

parametrize overwrites marks instead of adding #1387

Closed
vladimirlagunov opened this issue Feb 15, 2016 · 5 comments
Closed

parametrize overwrites marks instead of adding #1387

vladimirlagunov opened this issue Feb 15, 2016 · 5 comments

Comments

@vladimirlagunov
Copy link

I expect that all these test should pass.

# conftest.py
import pytest

TEST_PATHS = {}


@pytest.fixture
def paths_dict():
    return TEST_PATHS


def pytest_collection_modifyitems(session, config, items):
    for item in items:
        mark = item.get_marker('path')
        if mark is not None:
            TEST_PATHS[item.nodeid] = ','.join(sorted(mark.args))
# test_something.py
import pytest


@pytest.mark.path('class')
class TestFoo(object):
    @pytest.mark.path('method')
    def test_foo(self, request, paths_dict):
        assert paths_dict[request.node.nodeid] == 'class,method'


@pytest.mark.path('class')
class TestBar(object):
    @pytest.mark.parametrize('x', [
        pytest.mark.path('method-param')(1),
        2,
    ])
    @pytest.mark.path('method')
    def test_bar(self, request, paths_dict, x):
        if x == 1:
            assert paths_dict[request.node.nodeid] == 'class,method,method-param'
        else:
            assert paths_dict[request.node.nodeid] == 'class,method'


@pytest.mark.path('class')
@pytest.mark.parametrize('x', [
    pytest.mark.path('class-param')(1),
    2,
])
class TestBaz(object):
    @pytest.mark.path('method')
    def test_baz(self, request, paths_dict, x):
        if x == 1:
            assert paths_dict[request.node.nodeid] == 'class,class-param,method'
        else:
            assert paths_dict[request.node.nodeid] == 'class,method'

But tests that have marks on parameters fails because parametrize owerrites marks instead of adding them:

$ py.test . --tb=native
====================== test session starts ======================
platform linux -- Python 3.4.3+, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: /tmp/foo, inifile: 
collected 5 items 

test_foo.py .F.F.

=========================== FAILURES ============================
______________________ TestBar.test_bar[1] ______________________
Traceback (most recent call last):
  File "/tmp/foo/test_foo.py", line 21, in test_bar
    assert paths_dict[request.node.nodeid] == 'class,method,method-param'
AssertionError: assert 'method-param' == 'class,method,method-param'
  - method-param
  + class,method,method-param
______________________ TestBaz.test_baz[1] ______________________
Traceback (most recent call last):
  File "/tmp/foo/test_foo.py", line 35, in test_baz
    assert paths_dict[request.node.nodeid] == 'class,class-param,method'
AssertionError: assert 'class-param' == 'class,class-param,method'
  - class-param
  + class,class-param,method
============== 2 failed, 3 passed in 0.02 seconds ===============

OS: Ubuntu 15.10
Affects Python 2.7 and Python 3.4
py.test 2.8.7 from PyPI

@RonnyPfannschmidt
Copy link
Member

unfortunately that's a known bug, see #725
i'm closing this one as duplicate

i'm sorry for your inconvenience, this one is one of those that are in very hard to properly fix without breaking other test-suites

vladimirlagunov pushed a commit to vladimirlagunov/pytest that referenced this issue Feb 15, 2016
@vladimirlagunov
Copy link
Author

I don't know about your style and architecture agreements, but I've wrote fix for exactly this bug and it does not spoil any other test case (checked on py27 and py34).

Look at this diff. https://github.com/pytest-dev/pytest/compare/master...werehuman:fix-parametrize-overwrite-keywords?expand=1 If you're like it, I'll write comments and submit a pull request.

@RonnyPfannschmidt
Copy link
Member

at first glace it looks like a solution, but there is a problem,
it does not consider/interact with marker transfer, which is the root cause of the problem,
i recall that @hpk42 has a wip patch on this, so i feel bad about delaying your solution, which does indeed solve your problem

we will come to a conclusion in a few days, sorry for your inconvenience

@vladimirlagunov
Copy link
Author

Can you show me some places in code where marker transfer properly works now?

@RonnyPfannschmidt
Copy link
Member

that's the problem, they are not accessible in any way as of now

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

No branches or pull requests

2 participants