Running the initial tests

Since we're using test-driven design, we expect our tests to fail at first. And indeed our test fails spectacularly for the simple reason that we haven't yet defined analyze_text():

$ python text_analyzer.py
E
======================================================================
ERROR: test_function_runs (__main__.TextAnalysisTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "text_analyzer.py", line 5, in test_function_runs
analyze_text()
NameError: global name 'analyze_text' is not defined

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)

As you can see, unittest.main() produces a simple report telling us how many tests were run and how many failed. It also shows us how the tests failed, in this case showing us that we got a NameError when we tried to run the non-existent function analyze_text().

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset