I have a web server that returns HTML containing the following:
<div class="well">
<blockquote>
<h2>Blueberry Pancakes Are Bomb</h2>
</blockquote>
</div>
I wrote a contrived functional test like so:
def test_page_has_blueberry_in_blockquote(self):
# User goes to inspire_my_palate page
self.browser.get('http://localhost:8000/inspire_my_palate')
# He sees a blockquote with a header containing 'Blueberry ...'
food_text = self.browser.find_element_by_xpath('//div[@class="well"]/blockquote/h2').text
self.assertIs(food_text, u'Blueberry Pancakes Are Bomb')
When I run the test, I get this error:
(foodie_env)fatman:foodie$ python functional_tests.py
.F
======================================================================
FAIL: test_page_has_blueberry_in_blockquote (__main__.NewVisitorNavbar)
----------------------------------------------------------------------
Traceback (most recent call last):
File "functional_tests.py", line 179, in test_page_has_blueberry_in_blockquote
self.assertIs(food_text, u'Blueberry Pancakes Are Bomb')
AssertionError: u'Blueberry Pancakes Are Bomb' is not u'Blueberry Pancakes Are Bomb'
----------------------------------------------------------------------
Ran 2 tests in 6.656s
FAILED (failures=1)
I've also tried:
self.assertIs(food_text, 'Blueberry Pancakes Are Bomb')
Casting the string as unicode or not doesn't appear to change anything. I still get the same assertion error.
Update: I get a passing test if I change the assertion test to:
self.assertEquals(food_text, u'Blueberry Pancakes Are Bomb')
However, I'd still still like to know why the assertIs() test fails. I'm guessing this is due to how the strings are represented in memory. Intuitively, the assertIs() version should pass since I'm comparing two string types.
The assertion error is not very intuitive and is confusing. What could be causing this weird assertion error?
Aucun commentaire:
Enregistrer un commentaire