New issue 725: Markers are transferred from subclasses to base class methods
https://bitbucket.org/pytest-dev/pytest/issue/725/markers-are-transferred-from-subclasses-to
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
class Test1(BaseClass):
@pytest.mark.test1
def test_test1(self):
pass
class Test2(BaseClass):
@pytest.mark.test2
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
```
_______________________________________________
pytest-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-commit