TDD with python book, functional test does not find assertRegex

After test development with python book I got stuck I tried several different imports but still nothing ... anyone?

Error

$python manage.py test functional_tests ERROR: test_can_start_a_list_and_retrieve_it_later (functional_tests.tests.NewVisitorTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/coelhao/DjangoProjects/superlists/functional_tests/tests.py", line 45, in test_can_start_a_list_and_retrieve_it_later self.assertRegex(edith_list_url, '/lists/.+') AttributeError: 'NewVisitorTest' object has no attribute 'assertRegex' 

code

 from django.test import LiveServerTestCase from selenium import webdriver from selenium.webdriver.common.keys import Keys import unittest class NewVisitorTest(LiveServerTestCase): def setUp(self): self.browser = webdriver.Firefox() self.browser.implicitly_wait(3) def tearDown(self): self.browser.quit() def test_can_start_a_list_and_retrieve_it_later(self): # ..... # When she hits enter, the page updates, and now the page lists # "1: Buy peacock feathers" as an item in a to-do list table inputbox.send_keys(Keys.ENTER) edith_list_url = self.browser.current_url self.assertRegex(edith_list_url, '/lists/.+') self.check_for_row_in_list_table('1: Buy peacock feathers') # .... 
+6
source share
2 answers

I assume that you are in Python 2 and then assertRegexpMatches instead of assertRegex .

assertRegex was introduced in Python 3:

Changed in version 3.2: The assertRegexpMatches () method has been renamed to assertRegex ().

+14
source

There is no such assertion as assertRegex - perhaps you mean assertRegexMatches ?

Unittest docs are here: http://docs.python.org/2.7/library/unittest.html#unittest.TestCase

-1
source

Source: https://habr.com/ru/post/951914/


All Articles