Originally reported by: eduardo schettino (BitBucket: schettino72, GitHub: schettino72)
It seems that when a staticmethod is monkeypatched it is not restored/undo correctly.
#!python
from mock import Mock
class Sample(object):
@staticmethod
def hello():
return True
def test_1(monkeypatch):
monkeypatch.setattr(Sample, 'hello', Mock(return_value=False))
assert not Sample.hello()
def test_2():
assert Sample.hello()
#!python
$ py.test -v pytest_bug.py
================================== test session starts ==================================
platform linux2 -- Python 2.7.3 -- pytest-2.2.4 -- /home/eduardo/work/py27/bin/python
collected 2 items
pytest_bug.py:8: test_1 PASSED
pytest_bug.py:12: test_2 FAILED
======================================= FAILURES ========================================
________________________________________ test_2 _________________________________________
def test_2():
> assert Sample.hello()
E TypeError: unbound method hello() must be called with Sample instance as first argument (got nothing instead)
pytest_bug.py:13: TypeError
========================== 1 failed, 1 passed in 0.01 seconds ===========================
#!python
py.test -v pytest_bug.py -k test_2
================================== test session starts ==================================
platform linux2 -- Python 2.7.3 -- pytest-2.2.4 -- /home/eduardo/work/py27/bin/python
collected 2 items
pytest_bug.py:12: test_2 PASSED
=========================== 1 tests deselected by '-ktest_2' ============================
======================== 1 passed, 1 deselected in 0.01 seconds =========================
Originally reported by: eduardo schettino (BitBucket: schettino72, GitHub: schettino72)
It seems that when a staticmethod is monkeypatched it is not restored/undo correctly.