使用 pytest 运行单元测试时出错 - AttributeError:

我正在使用 pytest 5.4.1 和 python 3.6


代码:


import unittest


class TestStringMethods(unittest.TestCase):


    def test_upper(self):

        self.assertEqual('foo'.upper(), 'FOO')


if __name__ == '__main__':

    unittest.main()

运行报pytest如下错误:


Testing started at 06:08 ...

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


可能是什么问题?


繁星coding
浏览 576回答 2
2回答

一只名叫tom的猫

问题是get_marker已经改名了get_closest_marker 。在GitHub 上的这个问题中,您可以看到 @arvindpdmn 建议升级pytest-remotedata==0.3.0到pytest-remotedata==0.3.2,因此假设您用于pip安装依赖项,请运行以下命令:pip&nbsp;install&nbsp;-U&nbsp;pytest-remotedata

至尊宝的传说

如错误输出所示,问题出在 pytest-remotedata 包中。AttributeError:&nbsp;'TestCaseFunction'&nbsp;object&nbsp;has&nbsp;no&nbsp;attribute&nbsp;'get_marker' c:\program&nbsp;files&nbsp;(x86)\microsoft&nbsp;visual&nbsp;studio\shared\anaconda3_64\lib\site-packages\pytest_remotedata\plugin.py:59:&nbsp;AttributeErrorpytest-remotedata将软件包升级到最新版本 (0.3.2)后错误得到解决:pip&nbsp;install&nbsp;--upgrade&nbsp;pytest-remotedata
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python