[Pytest-commit] Issue #473: Cannot use @mark and multiple @patch class decorators (hpk42/pytest)

Dan Kinder issues-reply at bitbucket.org
Tue Mar 4 20:47:24 CET 2014


New issue 473: Cannot use @mark and multiple @patch class decorators
https://bitbucket.org/hpk42/pytest/issue/473/cannot-use-mark-and-multiple-patch-class

Dan Kinder:

Forgive me if this isn't intended to work, but I imagine it should.

This small test works:
```
#!python
from pytest import mark
from mock import patch

@patch('os.path')
@mark.slow
class TestSimple:
    def test_simple_thing(self, mock_path):
        pass
```

As well as this one:
```
#!python
from mock import patch

@patch('os.getcwd')
@patch('os.path')
class TestSimple:
    def test_simple_thing(self, mock_path, mock_getcwd):
        pass
```

But this one fails:
```
#!python
from pytest import mark
from mock import patch

# Note: the decorator order does not matter
@patch('os.getcwd')
@patch('os.path')
@mark.slow
class TestSimple:
    def test_simple_thing(self, mock_path, mock_getcwd):
        pass
```

(On python 2.6.6, pytest 2.5.2, mock 1.0.1)

The failure:
```
$ py.test
=========================================================== test session starts ===========================================================
platform linux2 -- Python 2.6.6 -- py-1.4.20 -- pytest-2.5.2
collected 0 items / 1 errors 

================================================================= ERRORS ==================================================================
_______________________________________________________ ERROR collecting test_a.py ________________________________________________________
../venv/lib/python2.6/site-packages/_pytest/runner.py:139: in __init__
>               self.result = func()
../venv/lib/python2.6/site-packages/_pytest/main.py:419: in _memocollect
>       return self._memoizedcall('_collected', lambda: list(self.collect()))
../venv/lib/python2.6/site-packages/_pytest/main.py:296: in _memoizedcall
>           res = function()
../venv/lib/python2.6/site-packages/_pytest/main.py:419: in <lambda>
>   return self._memoizedcall('_collected', lambda: list(self.collect()))
../venv/lib/python2.6/site-packages/_pytest/python.py:527: in collect
>       return super(Instance, self).collect()
../venv/lib/python2.6/site-packages/_pytest/python.py:321: in collect
>               res = self.makeitem(name, obj)
../venv/lib/python2.6/site-packages/_pytest/python.py:333: in makeitem
>           collector=self, name=name, obj=obj)
../venv/lib/python2.6/site-packages/_pytest/main.py:162: in call_matching_hooks
>       return hookmethod.pcall(plugins, **kwargs)
../venv/lib/python2.6/site-packages/_pytest/core.py:381: in pcall
>       return self._docall(methods, kwargs)
../venv/lib/python2.6/site-packages/_pytest/core.py:388: in _docall
>           res = mc.execute()
../venv/lib/python2.6/site-packages/_pytest/core.py:289: in execute
>           res = method(**kwargs)
../venv/lib/python2.6/site-packages/_pytest/python.py:227: in pytest_pycollect_makeitem
>               return list(collector._genfunctions(name, obj))
../venv/lib/python2.6/site-packages/_pytest/python.py:339: in _genfunctions
>       transfer_markers(funcobj, cls, module)
../venv/lib/python2.6/site-packages/_pytest/python.py:435: in transfer_markers
>                   mark(funcobj)
../venv/lib/python2.6/site-packages/_pytest/mark.py:264: in __call__
>                       setattr(func, self.name, holder)
E                       AttributeError: 'instancemethod' object has no attribute 'slow'
========================================================= 1 error in 0.07 seconds =========================================================
```

If this work and is a pytest problem (not the mock library or something else) and should work, let me know and I may be able to dive in and try to patch it up.




More information about the pytest-commit mailing list