Python 使用pytest运行单元测试时出错-AttributeError:';TestCaseFunction';对象没有属性';获取标记';

Python 使用pytest运行单元测试时出错-AttributeError:';TestCaseFunction';对象没有属性';获取标记';,python,python-3.x,pytest,Python,Python 3.x,Pytest,我将Pytest5.4.1与Python3.6一起使用 代码: 运行pytest会出现以下错误: Testing started at 06:08 ... "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\python.exe" "C:\Program Files\JetBrains\PyCharm Community Edition 2019.2\helpers\pycharm\

我将Pytest5.4.1与Python3.6一起使用

代码:

运行
pytest
会出现以下错误:

Testing started at 06:08 ...
"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\python.exe" "C:\Program Files\JetBrains\PyCharm Community Edition 2019.2\helpers\pycharm\_jb_pytest_runner.py" --path E:/Folder1/Project1/src/Project1.Api/tests/test1.py
Launching pytest with arguments E:/Folder1/Project1/src/Project1.Api/tests/test1.py in E:\Folder1\Project1\src\Project1.Api\tests

============================= test session starts =============================
platform win32 -- Python 3.6.5, pytest-5.4.1, py-1.5.3, pluggy-0.13.1 -- C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\python.exe
cachedir: .pytest_cache
rootdir: E:\Folder1\Project1\src\Project1.Api\tests
plugins: arraydiff-0.2, cov-2.8.1, doctestplus-0.1.3, openfiles-0.3.0, remotedata-0.2.1
collecting ... collected 1 item

test1.py::TestStringMethods::test_upper ERROR                            [100%]
test setup failed
item = <TestCaseFunction test_upper>

    def pytest_runtest_setup(item):
    
>       remote_data = item.get_marker('remote_data')
E       AttributeError: 'TestCaseFunction' object has no attribute 'get_marker'

c:\program files (x86)\microsoft visual studio\shared\anaconda3_64\lib\site-packages\pytest_remotedata\plugin.py:59: AttributeError

Assertion failed


=================================== ERRORS ====================================
_______________ ERROR at setup of TestStringMethods.test_upper ________________

item = <TestCaseFunction test_upper>

    def pytest_runtest_setup(item):
    
>       remote_data = item.get_marker('remote_data')
E       AttributeError: 'TestCaseFunction' object has no attribute 'get_marker'

c:\program files (x86)\microsoft visual studio\shared\anaconda3_64\lib\site-packages\pytest_remotedata\plugin.py:59: AttributeError
=========================== short test summary info ===========================
ERROR test1.py::TestStringMethods::test_upper - AttributeError: 'TestCaseFunc...
============================== 1 error in 0.04s ===============================

Process finished with exit code 0

Assertion failed

Assertion failed
测试于06:08开始。。。
“C:\Program Files(x86)\Microsoft Visual Studio\Shared\Anaconda3\u 64\python.exe”“C:\Program Files\JetBrains\PyCharm Community Edition 2019.2\helpers\PyCharm\\u jb\u pytest\u runner.py”--路径E:/Folder1/Project1/src/Project1.Api/tests/test1.py
在E:\Folder1\Project1\src\Project1.Api\tests中使用参数E:/Folder1/Project1/src/Project1.Api/tests/test1.py启动pytest
===========================================测试会话开始=============================
平台win32--Python 3.6.5、pytest-5.4.1、py-1.5.3、Plugy-0.13.1--C:\Program Files(x86)\Microsoft Visual Studio\Shared\Anaconda3\u 64\Python.exe
cachedir:.pytest\u缓存
rootdir:E:\Folder1\Project1\src\Project1.Api\tests
插件:arraydiff-0.2、cov-2.8.1、doctestplus-0.1.3、openfiles-0.3.0、remotedata-0.2.1
收集。。。收集1项
test1.py::TestStringMethods::test\u上限错误[100%]
测试设置失败
项目=
def pytest_运行测试_设置(项目):
>远程\u数据=项。获取\u标记(“远程\u数据”)
E AttributeError:'TestCaseFunction'对象没有属性'get\u marker'
c:\program files(x86)\microsoft visual studio\shared\anaconda3\u 64\lib\site packages\pytest\u remotedata\plugin.py:59:AttributeError
断言失败
===================================================错误====================================
_______________设置TestStringMethods.test\u时出错________________
项目=
def pytest_运行测试_设置(项目):
>远程\u数据=项。获取\u标记(“远程\u数据”)
E AttributeError:'TestCaseFunction'对象没有属性'get\u marker'
c:\program files(x86)\microsoft visual studio\shared\anaconda3\u 64\lib\site packages\pytest\u remotedata\plugin.py:59:AttributeError
==============================================短测试摘要信息===========================
错误test1.py::TestStringMethods::test_upper-AttributeError:'TestCaseFunc。。。
=================================================0.04秒内出现1个错误===============================
进程已完成,退出代码为0
断言失败
断言失败

可能是什么问题?

从错误输出中可以看出,问题出在pytest remotedata包中

AttributeError: 'TestCaseFunction' object has no attribute 'get_marker'

c:\program files (x86)\microsoft visual studio\shared\anaconda3_64\lib\site-packages\pytest_remotedata\plugin.py:59: AttributeError
pytest-remotedata
软件包升级到最新版本(0.3.2)后,错误得到解决:


问题是
get\u marker
已被重命名为
get\u closest\u marker
。在GitHub上,您可以看到@arvindpdmn建议将
pytest-remotedata==0.3.0
升级到
pytest-remotedata==0.3.2
,因此假设您使用
pip
安装依赖项,请运行以下命令:

pip安装-U pytest remotedata

如果没有任何代码可供查看,很难找出问题所在,因为您正在调用get_marker()在TestCaseFunction上,它显然没有get_marker属性。现在使用unittest代码和完整输出更新。对于我来说,它正在运行。您有什么版本的pytest cov和pytest remotedata?pytest cov==2.8.1;pytest remotedata==0.2.1
AttributeError: 'TestCaseFunction' object has no attribute 'get_marker'

c:\program files (x86)\microsoft visual studio\shared\anaconda3_64\lib\site-packages\pytest_remotedata\plugin.py:59: AttributeError
pip install --upgrade pytest-remotedata