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
Closed

Markers are transferred from subclasses to base class methods #725

pytestbot opened this issue Apr 17, 2015 · 1 comment
Labels
status: critical grave problem or usability issue that affects lots of users type: backward compatibility might present some backward compatibility issues which should be carefully noted in the changelog type: bug problem that needs to be addressed type: refactoring internal improvements to the code
Milestone

Comments

@pytestbot
Copy link
Contributor

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

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
@RonnyPfannschmidt RonnyPfannschmidt modified the milestones: 2.8, 3.0 Sep 13, 2015
@RonnyPfannschmidt RonnyPfannschmidt added type: backward compatibility might present some backward compatibility issues which should be carefully noted in the changelog status: critical grave problem or usability issue that affects lots of users type: refactoring internal improvements to the code labels Dec 30, 2015
@nicoddemus
Copy link
Member

Duplicate of #568

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: critical grave problem or usability issue that affects lots of users type: backward compatibility might present some backward compatibility issues which should be carefully noted in the changelog type: bug problem that needs to be addressed type: refactoring internal improvements to the code
Projects
None yet
Development

No branches or pull requests

4 participants