简体   繁体   中英

AttributeError: type object 'TestPages' has no attribute 'test_sort_by_price'

For some reason I can't run ddt.py. Could you explain what is the problem? In official documentation it looks like this.

@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:

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'

first, rename ddt.py to test_dtt.py to avoid confusion of lib

second, find . -name "*dtt*.py*" find . -name "*dtt*.py*" , rename them properly

last, find and remove any *.pyc files and rerun the tests

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

The problem is that you run separate test, not the test class itself. Try to run test class, it worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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