2013-08-16 15 views
6

Dopo lo sviluppo guidato da test con il libro Python mi sono bloccato Ho provato diverse importazioni diverse ma ancora niente .. qualcuno?TDD con libro Python, test funzionale non trova assertRegex

errore

$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' 

Codice

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') 

     # .... 

risposta

14

sto assumendo si è in Python 2 - quindi utilizzare assertRegexpMatches invece di assertRegex.

assertRegex è stato introdotto in Python 3:

Modificato nella versione 3.2: Il metodo assertRegexpMatches() è stato rinominato assertRegex().

-1

Non esiste tale asserzione come assertRegex - forse si intende assertRegexMatches?

La documentazione unittest sono qui: http://docs.python.org/2.7/library/unittest.html#unittest.TestCase

+0

si potrebbe desiderare di guardare nella documentazione Python 3: https://docs.python.org/3.2/library/unittest.html#unittest.TestCase.assertRegex –