繁体   English   中英

AttributeError:类型对象“TestPages”没有属性“test_sort_by_price”

[英]AttributeError: type object 'TestPages' has no attribute 'test_sort_by_price'

出于某种原因,我无法运行 ddt.py。 你能解释一下是什么问题吗? 在官方文档中它看起来像这样。

@ddt
class TestPages(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.set_page_load_timeout(10)
        self.driver.maximize_window()

    @file_data('client.json')
    def test_sort_by_price(self, value):
        print("\n" + str(test_cases(2)))
        gallerypage = GalleryPage(self.driver, value)
        result = gallerypage.sort_by_price()
        self.assertTrue(result)

错误:

Error
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 605, in run
    testMethod()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 34, in testFailure
    raise self._exception
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 168, in loadTestsFromName
    parent, obj = obj, getattr(obj, part)
AttributeError: type object 'TestPages' has no attribute 'test_sort_by_price'

首先,将ddt.py重命名为test_dtt.py以避免混淆lib

第二, find . -name "*dtt*.py*" find . -name "*dtt*.py*" ,将其正确重命名

最后,找到并删除任何*.pyc文件,然后重新运行测试

for file in `find . -name "*.pyc"`; do rm -vf $file; done

问题是您运行单独的测试,而不是测试类本身。 尝试运行测试类,它对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM