我有一个测试类,其中包含一些静态方法和普通方法。问题是pytest
不收集静态方法。我在文档中找不到与此相关的任何内容。我怎样才能让它也收集静态方法?
class TestFoo(object):
@staticmethod
def test_bar():
assert 1 == 1
def test_bar2(self):
assert 1 == 1
在上面的类中,仅test_bar2
被收集并且test_bar()
isn't.
我在跑步Python 2.7.13, pytest-3.1.2, py-1.4.34, pluggy-0.4.0
插件有xdist-1.17.1, leaks-0.2.2, cov-2.5.1
收集测试函数时,pytest 确保每个函数都是可调用的 https://github.com/pytest-dev/pytest/blob/4e57a39067ddf1973ca2a6207423fdcd5916fa2e/_pytest/python.py#L273.
But a 静态法不可调用,来自https://docs.python.org/3/reference/datamodel.html https://docs.python.org/3/reference/datamodel.html:
静态方法对象本身是不可调用的,尽管它们包装的对象通常是可调用的。
see:
>>> class TestFoo(object):
... @staticmethod
... def test_bar():
... assert 1 == 1
...
>>> hasattr(TestFoo.__dict__['test_bar'], '__call__')
False
为此,pytest 本身应该修改为接受静态方法,我不知道这是否是他们想要的,如果你认为你确实需要它,你可以在 github 上的问题跟踪器上打开一个问题。
为什么您认为静态方法是一种解决方案?具体针对哪个问题?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)