Skip to Content
Mastering Flask Web Development - Second Edition
book

Mastering Flask Web Development - Second Edition

by Daniel Gaspar, Jack Stouffer
October 2018
Intermediate to advanced
332 pages
8h 9m
English
Packt Publishing
Content preview from Mastering Flask Web Development - Second Edition

Testing the route functions

Let's build our first test case. In this test case, we will be testing if the route functions successfully return a response when we access its URL. In a new directory named tests, at the root of the project directory, create a new file named test_urls.py, which will hold all of the unit tests for the routes. Each test case should have its own file, and each test case should focus on one area of the code that you are testing.

In test_urls.py, let's start creating what the built-in Python unittest library needs. The code will use the unittest library from Python in order to run all the tests that we create in the test case:

import unittest class TestURLs(unittest.TestCase): pass if __name__ == '__main__': unittest.main() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Flask Web Development, 2nd Edition

Flask Web Development, 2nd Edition

Miguel Grinberg
Flask Web Development

Flask Web Development

Miguel Grinberg

Publisher Resources

ISBN: 9781788995405Supplemental Content