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

Markers are transferred from subclasses to base class methods #725

Closed
pytestbot opened this Issue Apr 17, 2015 · 1 comment

Comments

Projects
None yet
4 participants
@pytestbot
Copy link

pytestbot commented Apr 17, 2015

Originally reported by: BitBucket: foobarbazquux, GitHub: foobarbazquux


pytest transfers markers from subclasses to base class methods, which can result in incorrect test selection.

Example code:

#!python
import pytest

class BaseClass():
    def test_foo(self):
        pass

@pytest.mark.test1
class Test1(BaseClass):
    def test_test1(self):
        pass

@pytest.mark.test2
class Test2(BaseClass):
    def test_test2(self):
        pass

Example run showing the test1 marker also being applied to the Test2 base class:

$ py.test -v --collect-only -m test1
================================================================================ test session starts ================================================================================
platform darwin -- Python 2.7.8 -- py-1.4.26 -- pytest-2.6.4 -- /usr/local/opt/python/bin/python2.7
collected 4 items
<Module 'test_example.py'>
  <Class 'Test1'>
    <Instance '()'>
      <Function 'test_foo'>
      <Function 'test_test1'>
  <Class 'Test2'>
    <Instance '()'>
      <Function 'test_foo'>

======================================================================== 1 tests deselected by "-m 'test1'" =========================================================================
=========================================================================== 1 deselected in 0.01 seconds ===========================================================================

More detail from ronny via IRC:

1:52 ronny joesmith: ah, i figured the bug
1:52 ronny hpk: marker transfer to base class test methods fails
1:52 ronny joesmith: we have a mechanism that transfers test markers from the classes to the methods
1:53 ronny joesmith: due to a misstake they trasnfer subclass markers to base class methods
1:53 ronny can you report a issue, i think we can issue a fix this weekend
1:55 ronny hpk: markers on a subclass transfer to a base class method
1:57 ronny https://bitbucket.org/pytest-dev/pytest/src/tip/_pytest/python.py#cl-351 is the "bad" call site
1:58 ronny and https://bitbucket.org/pytest-dev/pytest/src/tip/_pytest/python.py#cl-437 is the implementation
2:01 ronny hpk: its not an easy fix ^^
2:02 ronny hpk: as far as i can tell marker transfer should be part of the marker plugin and the item marker set should be detached from the per object markers
2:03 ronny its a minor restructuring but it has external facing api implications

@nicoddemus

This comment has been minimized.

Copy link
Member

nicoddemus commented Mar 18, 2016

Duplicate of #568

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.