解决pytest.mark.dependency的scope为package报AttributeError: ‘NoneType‘ object has no attribute..

在上一篇文章中,我们执行scope='package’时报如下错:

D:\pythonProject\dependency\dep\dep2>pytest -sv
======================================================================== test session starts ========================================================================
platform win32 -- Python 3.7.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- d:\python3.7.6\python.exe
cachedir: .pytest_cache
rootdir: D:\pythonProject\dependency\dep\dep2
plugins: allure-pytest-2.9.41, dependency-0.5.1
collected 6 items                                                                                                                                                    

test_dep_01.py::Testna::test_01 function test_01
PASSED
test_dep_01.py::Testna::test_02 function test_02
PASSED
test_dep_02.py::test_02 function test_02
PASSED
test_dep_02.py::Testdep1::test_01 class test_01
PASSED
test_dep_02.py::Testdep1::test_02 ERROR
test_dep_02.py::test_01 function test_01
PASSED

============================================================================== ERRORS ===============================================================================
________________________________________________________________ ERROR at setup of Testdep1.test_02 _________________________________________________________________

item = <Function test_02>

    def pytest_runtest_setup(item):
        """Check dependencies if this item is marked "dependency".
        Skip if any of the dependencies has not been run successfully.
        """
        marker = item.get_closest_marker("dependency")
        if marker is not None:
            depends = marker.kwargs.get('depends')
            if depends:
                scope = marker.kwargs.get('scope', 'module')
                manager = DependencyManager.getManager(item, scope=scope)
>               manager.checkDepend(depends, item)
E               AttributeError: 'NoneType' object has no attribute 'checkDepend'

D:\python3.7.6\lib\site-packages\pytest_dependency.py:179: AttributeError
====================================================================== short test summary info ======================================================================
ERROR test_dep_02.py::Testdep1::test_02 - AttributeError: 'NoneType' object has no attribute 'checkDepend'
==================================================================== 5 passed, 1 error in 0.10s =====================================================================

明明设置的@pytest.mark.dependency(depends=[“test_dep_01.py::Testna::test_01”]中的方法也已经执行了,为什么还报错了?

解决方法是:在dep2目录下增加__init__.py文件即可。 _init_.py文件内容是空的。关于_init__.py文件的作用后面我们再介绍。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

永远不要矫情

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值