TDD is a process where the developer takes personal responsibility for the quality of his code.
Steps:
Benefits:
Different kind of tests:
Workflow of testing:
unnecessary_math.py
'''
Module showing how doctests can be included with source code
Each '>>>' line is run as if in a python shell, and counts as a test.
The next line, if not '>>>' is the expected output of the previous line.
If anything doesn't match exactly (including trailing spaces), the test fails.
'''
def multiply(a, b):
"""
>>> multiply(4, 3)
12
>>> multiply('a', 3)
'aaa'
"""
return a * b
The doctest test framework is a python module that comes prepackaged with Python.
Running doctest:
python -m doctest -v <file>
$ python -m doctest -v unnecessary_math.py
Trying:
multiply(4, 3)
Expecting:
12
ok
Trying:
multiply('a', 3)
Expecting:
'aaa'
ok
1 items had no tests:
unnecessary_math
1 items passed all tests:
2 tests in unnecessary_math.multiply
2 tests in 2 items.
2 passed and 0 failed.
Test passed.
Running doctest in seperate file:
test_unnecessary_math.txt
This is a doctest based regression suite for unnecessary_math.py
Each '>>' line is run as if in a python shell, and counts as a test.
The next line, if not '>>' is the expected output of the previous line.
If anything doesn't match exactly (including trailing spaces), the test fails.
>>> from unnecessary_math import multiply
>>> multiply(3, 4)
12
>>> multiply('a', 3)
'aaa'
Output:
$ python -m doctest -v test_unnecessary_math.txt
Trying:
from unnecessary_math import multiply
Expecting nothing
ok
Trying:
multiply(3, 4)
Expecting:
12
ok
Trying:
multiply('a', 3)
Expecting:
'aaa'
ok
1 items passed all tests:
3 tests in test_unnecessary_math.txt
3 tests in 1 items.
3 passed and 0 failed.
Test passed.
The unittest test framework is python’s xUnit style framework. It is a standard module that you already have if you’ve got python version 2.1 or greater.
We will be using same unnecessary_math.py module as earlier.
test_um_unittest.py
import unittest
from unnecessary_math import multiply
class TestUM(unittest.TestCase):
def setUp(self):
pass
def test_numbers_3_4(self):
self.assertEqual( multiply(3,4), 12)
def test_strings_a_3(self):
self.assertEqual( multiply('a',3), 'aaa')
if __name__ == '__main__':
unittest.main()
Run code:
$ python test_um_unittest.py -v
test_numbers_3_4 (__main__.TestUM) ... ok
test_strings_a_3 (__main__.TestUM) ... ok
Nose’s tagline is “nose extends unittest to make testing easier”. It’s is a fairly well known python unit test framework, and can run doctests, unittests, and “no boilerplate” tests.
You have to install nose:
pip install nose
Example:
test_um_nose.py
from unnecessary_math import multiply
def test_numbers_3_4():
assert multiply(3,4) == 12
def test_strings_a_3():
assert multiply('a',3) == 'aaa'
Run code:
$ nosetests -v test_um_nose.py
test_um_nose.test_numbers_3_4 ... ok
test_um_nose.test_strings_a_3 ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.003s
OK
Nose extends unittests possibilities. We can add specific code to run:
at the beginning and end of a module of test code (setup_module/teardown_module) To get this to work, you just have to use the right naming rules.
at the beginning and end of a class of test methods (setup_class/teardown_class) To get this to work, you have to use the right naming rules, and include the ‘@classmethod’ decorator.
before and after a test function call (setup_function/teardown_function) You can use any name. You have to apply them with the ‘@with_setup’ decorator imported from nose. You can also use direct assignment, which I’ll show in the example.
before and after a test method call (setup/teardown) To get this to work, you have to use the right name.
Full example:
from nose import with_setup # optional
from unnecessary_math import multiply
def setup_module(module):
print("") # this is to get a newline after the dots
print("setup_module before anything in this file")
def teardown_module(module):
print("teardown_module after everything in this file")
def my_setup_function():
print("my_setup_function")
def my_teardown_function():
print("my_teardown_function")
@with_setup(my_setup_function, my_teardown_function)
def test_numbers_3_4():
print('test_numbers_3_4 <============================ actual test code')
assert multiply(3,4) == 12
@with_setup(my_setup_function, my_teardown_function)
def test_strings_a_3():
print('test_strings_a_3 <============================ actual test code')
assert multiply('a',3) == 'aaa'
class TestUM:
def setup(self):
print("TestUM:setup() before each test method")
def teardown(self):
print("TestUM:teardown() after each test method")
@classmethod
def setup_class(cls):
print("setup_class() before any methods in this class")
@classmethod
def teardown_class(cls):
print("teardown_class() after any methods in this class")
def test_numbers_5_6(self):
print('test_numbers_5_6() <============================ actual test code')
assert multiply(5,6) == 30
def test_strings_b_2(self):
print('test_strings_b_2() <============================ actual test code')
assert multiply('b',2) == 'bb'
Result:
$ nosetests -s test_um_nose_fixtures.py
setup_module before anything in this file
setup_class() before any methods in this class
TestUM:setup() before each test method
test_numbers_5_6() <============================ actual test code
TestUM:teardown() after each test method
.TestUM:setup() before each test method
test_strings_b_2() <============================ actual test code
TestUM:teardown() after each test method
.teardown_class() after any methods in this class
my_setup_function
test_numbers_3_4 <============================ actual test code
my_teardown_function
.my_setup_function
test_strings_a_3 <============================ actual test code
my_teardown_function
.teardown_module after everything in this file
----------------------------------------------------------------------
Ran 4 tests in 0.002s
OK
First, you have to install pytest:
pip install pytest
Unit test counterpart code:
import unittest
from unnecessary_math import multiply
class TestUM(unittest.TestCase):
def test_numbers_3_4(self):
self.assertEqual( multiply(3,4), 12)
Pytest version:
from unnecessary_math import multiply
def test_numbers_3_4():
assert( multiply(3,4) == 12 )
There is no need to import unnittest.
There is no need to derive from TestCase.
There is no need to for special self.assertEqual(), since we can use Python’s built in assert statement.
test_um_pytest.py
from unnecessary_math import multiply
def test_numbers_3_4():
assert multiply(3,4) == 12
def test_strings_a_3():
assert multiply('a',3) == 'aaa'
Run tests:
python -m pytest -v test_um_pytest.py
py.test -v test_um_pytest.py
Result:
py.test -v test_um_pytest.py
============================================================================================================ test session starts =============================================================================================================
platform darwin -- Python 3.7.0, pytest-3.8.0, py-1.6.0, pluggy-0.7.1 -- /Users/jasiplum/Development/Projects/Tieto/Python/naucse/venv/bin/python
cachedir: .pytest_cache
rootdir: /Users/jasiplum/Development/Projects/Tieto/Python/naucse, inifile:
collected 2 items
test_um_pytest.py::test_numbers_3_4 PASSED [ 50%]
test_um_pytest.py::test_strings_a_3 PASSED [100%]
========================================================================================================== 2 passed in 0.07 seconds ==========================================================================================================
Although unittest does allow us to have setup and teardown, pytest extends this quite a bit. We can add specific code to run:
Full example test_um_pytest2.py:
from unnecessary_math import multiply
def setup_module(module):
print("setup_module module:%s" % module.__name__)
def teardown_module(module):
print("teardown_module module:%s" % module.__name__)
def setup_function(function):
print("setup_function function:%s" % function.__name__)
def teardown_function(function):
print("teardown_function function:%s" % function.__name__)
def test_numbers_3_4():
print('test_numbers_3_4 <============================ actual test code')
assert multiply(3,4) == 12
def test_strings_a_3():
print('test_strings_a_3 <============================ actual test code')
assert multiply('a',3) == 'aaa'
class TestUM:
def setup(self):
print("setup class:TestStuff")
def teardown(self):
print("teardown class:TestStuff")
def setup_class(cls):
print("setup_class class:%s" % cls.__name__)
def teardown_class(cls):
print("teardown_class class:%s" % cls.__name__)
def setup_method(self, method):
print("setup_method method:%s" % method.__name__)
def teardown_method(self, method):
print("teardown_method method:%s" % method.__name__)
def test_numbers_5_6(self):
print('test_numbers_5_6 <============================ actual test code')
assert multiply(5,6) == 30
def test_strings_b_2(self):
print('test_strings_b_2 <============================ actual test code')
assert multiply('b',2) == 'bb'
``
Expected result:
$ py.test -v test_um_pytest2.py ============================================================================================================ test session starts ============================================================================================================= platform darwin -- Python 3.7.0, pytest-3.8.0, py-1.6.0, pluggy-0.7.1 -- /Users/jasiplum/Development/Projects/Tieto/Python/naucse/venv/bin/python cachedir: .pytest_cache rootdir: /Users/jasiplum/Development/Projects/Tieto/Python/naucse, inifile: collected 4 items
test_um_pytest2.py::test_numbers_3_4 PASSED [ 25%] test_um_pytest2.py::test_strings_a_3 PASSED [ 50%] test_um_pytest2.py::TestUM::test_numbers_5_6 PASSED [ 75%] test_um_pytest2.py::TestUM::test_strings_b_2 PASSED [100%]
========================================================================================================== 4 passed in 0.08 seconds ==========================================================================================================
You can also run unittests and doctest with pytest.
### Other testing tools
#### Unit tests
pytest-cov: display the test coverage of your project
pytest-flake8: linter to make sure that your code is following the PEP8 style
Tox: http://tox.readthedocs.io - Tox can automate the creation of separate environments to run your tests.
#### Functional tests
WebTest: http://webtest.readthedocs.io
#### Load tests
Apache Bench
Boom: https://github.com/tarekziade/boom
Molotov: https://github.com/tarekziade/molotov
locust.io: http://docs.locust.io
#### End-to-end tests
Selenium: http://docs.seleniumhq.org/
#### Tests coverage
coverage: https://coverage.readthedocs.io
### Developer documentation
Sphinx: http://www.sphinx-doc.org/
The following is a full example of a project documentation using Sphinx:
myservice is a simple JSON Flask application that uses Flakon.
The application is created with :func:flakon.create_app
:
.. literalinclude:: ../../myservice/app.py
The :file:settings.ini
file which is passed to :func:create_app
contains options for running the Flask app, like the DEBUG flag:
.. literalinclude:: ../../myservice/settings.ini
:language: ini
Blueprint are imported from :mod:myservice.views
and one
Blueprint and view example was provided in :file:myservice/views/home.py
:
.. literalinclude:: ../../myservice/views/home.py :name: home.py :emphasize-lines: 13
Views can return simple mappings (as highlighted in the example above), in that case, they will be converted into a JSON response. ```
Write simple production function and their unit tests with following test cases:
Use PyTest framework.
{ "data": { "sessionMaterial": { "id": "session-material:2019/tieto-ostrava-jaro:testing:0", "title": "Testing", "html": "\n \n \n\n <h2>Testing</h2>\n<h3>Test Driven Development (TDD)</h3>\n<blockquote><p>TDD is a process where the developer takes personal responsibility for the quality of his code.</p>\n</blockquote>\n<p>Steps:</p>\n<ul>\n<li>Unit tests are written before production code</li>\n<li>Don't write all tests or production code at once</li>\n<li>Small chunks of production code and tests are written together</li>\n</ul>\n<p>Benefits:</p>\n<ul>\n<li>Gives you confidence to change a code</li>\n<li>Gives you immediate feedback</li>\n<li>Documents what the code is doing</li>\n<li>Drives good object oriented design</li>\n</ul>\n<h3>TDD Work Flow</h3>\n<ul>\n<li>Write a failing unit test (red phase)</li>\n<li>Make the test pass (green phase)</li>\n<li>Refactor the code to make it clean (refactor phase)</li>\n<li>Repeat until the feature is complete</li>\n</ul>\n<p>Different kind of tests:</p>\n<ul>\n<li>Unit tests: Make sure a class or a function works as expected in isolation</li>\n<li>Functional tests: Verify that the service does what it says from the consumer's point of view, and behaves correctly even on bad requests</li>\n<li>Integration tests: Verify how (a service) integrates with all its network dependencies</li>\n<li>Load tests: Measure the service performances</li>\n<li>End-to-end tests: Verify that the whole system works with an end-to-end test</li>\n</ul>\n<p>Workflow of testing:</p>\n<ul>\n<li>Think about your new function or method. What feauture should provide?</li>\n<li>Write some skeleton of the code, so your program won't break. Your test should fail, so you are sure, that your test code is able to fail.</li>\n<li>Write dummy code for your skeleton, so your new code will pass the test. It doesn't have to fully functional code.</li>\n<li>Rewrite your code, so it does what suppose to do and make that test(s) passes.</li>\n</ul>\n<h3>Example code</h3>\n<p><strong>unnecessary_math.py</strong></p>\n<div class=\"highlight\"><pre><code>'''\nModule showing how doctests can be included with source code\nEach '>>>' line is run as if in a python shell, and counts as a test.\nThe next line, if not '>>>' is the expected output of the previous line.\nIf anything doesn't match exactly (including trailing spaces), the test fails.\n'''\n\ndef multiply(a, b):\n """\n >>> multiply(4, 3)\n 12\n >>> multiply('a', 3)\n 'aaa'\n """\n return a * b</code></pre></div><h3>Type of test</h3>\n<h4>doctests</h4>\n<p>The doctest test framework is a python module that comes prepackaged with Python.</p>\n<p>Running doctest:</p>\n<div class=\"highlight\"><pre><code>python -m doctest -v <file></code></pre></div><div class=\"highlight\"><pre><code>$ python -m doctest -v unnecessary_math.py\nTrying:\n multiply(4, 3)\nExpecting:\n 12\nok\nTrying:\n multiply('a', 3)\nExpecting:\n 'aaa'\nok\n1 items had no tests:\n unnecessary_math\n1 items passed all tests:\n 2 tests in unnecessary_math.multiply\n2 tests in 2 items.\n2 passed and 0 failed.\nTest passed.</code></pre></div><p>Running doctest in seperate file:</p>\n<p><strong>test_unnecessary_math.txt</strong></p>\n<div class=\"highlight\"><pre><code>This is a doctest based regression suite for unnecessary_math.py\nEach '>>' line is run as if in a python shell, and counts as a test.\nThe next line, if not '>>' is the expected output of the previous line.\nIf anything doesn't match exactly (including trailing spaces), the test fails.\n\n>>> from unnecessary_math import multiply\n>>> multiply(3, 4)\n12\n>>> multiply('a', 3)\n'aaa'</code></pre></div><p>Output:</p>\n<div class=\"highlight\"><pre><code>$ python -m doctest -v test_unnecessary_math.txt\nTrying:\n from unnecessary_math import multiply\nExpecting nothing\nok\nTrying:\n multiply(3, 4)\nExpecting:\n 12\nok\nTrying:\n multiply('a', 3)\nExpecting:\n 'aaa'\nok\n1 items passed all tests:\n 3 tests in test_unnecessary_math.txt\n3 tests in 1 items.\n3 passed and 0 failed.\nTest passed.</code></pre></div><h4>unittest</h4>\n<p>The unittest test framework is python’s xUnit style framework.\nIt is a standard module that you already have if you’ve got python version 2.1 or greater.</p>\n<p>We will be using same unnecessary_math.py module as earlier.</p>\n<p><strong>test_um_unittest.py</strong></p>\n<div class=\"highlight\"><pre><code>import unittest\nfrom unnecessary_math import multiply\n\nclass TestUM(unittest.TestCase):\n\n def setUp(self):\n pass\n\n def test_numbers_3_4(self):\n self.assertEqual( multiply(3,4), 12)\n\n def test_strings_a_3(self):\n self.assertEqual( multiply('a',3), 'aaa')\n\nif __name__ == '__main__':\n unittest.main()</code></pre></div><p>Run code:</p>\n<div class=\"highlight\"><pre><code>$ python test_um_unittest.py -v\ntest_numbers_3_4 (__main__.TestUM) ... ok\ntest_strings_a_3 (__main__.TestUM) ... ok</code></pre></div><h3>Nose</h3>\n<p>Nose’s tagline is “nose extends unittest to make testing easier”.\nIt’s is a fairly well known python unit test framework, and can run doctests, unittests, and “no boilerplate” tests.</p>\n<p>You have to install nose:</p>\n<div class=\"highlight\"><pre><code>pip install nose</code></pre></div><p>Example:</p>\n<p><strong>test_um_nose.py</strong></p>\n<div class=\"highlight\"><pre><code>from unnecessary_math import multiply\n\ndef test_numbers_3_4():\n assert multiply(3,4) == 12 \n\ndef test_strings_a_3():\n assert multiply('a',3) == 'aaa'</code></pre></div><p>Run code:</p>\n<div class=\"highlight\"><pre><code>$ nosetests -v test_um_nose.py\ntest_um_nose.test_numbers_3_4 ... ok\ntest_um_nose.test_strings_a_3 ... ok\n\n----------------------------------------------------------------------\nRan 2 tests in 0.003s\n\nOK</code></pre></div><p>Nose extends unittests possibilities. We can add specific code to run:</p>\n<ul>\n<li><p>at the beginning and end of a module of test code (setup_module/teardown_module)\nTo get this to work, you just have to use the right naming rules.</p>\n</li>\n<li><p>at the beginning and end of a class of test methods (setup_class/teardown_class)\nTo get this to work, you have to use the right naming rules, and include the ‘@classmethod’ decorator.</p>\n</li>\n<li><p>before and after a test function call (setup_function/teardown_function)\nYou can use any name. You have to apply them with the ‘@with_setup’ decorator imported from nose.\nYou can also use direct assignment, which I’ll show in the example.</p>\n</li>\n<li><p>before and after a test method call (setup/teardown)\nTo get this to work, you have to use the right name.</p>\n</li>\n</ul>\n<p>Full example:</p>\n<div class=\"highlight\"><pre><code>from nose import with_setup # optional\n\nfrom unnecessary_math import multiply\n\ndef setup_module(module):\n print("") # this is to get a newline after the dots\n print("setup_module before anything in this file")\n\ndef teardown_module(module):\n print("teardown_module after everything in this file")\n\ndef my_setup_function():\n print("my_setup_function")\n\ndef my_teardown_function():\n print("my_teardown_function")\n\n@with_setup(my_setup_function, my_teardown_function)\ndef test_numbers_3_4():\n print('test_numbers_3_4 <============================ actual test code')\n assert multiply(3,4) == 12\n\n@with_setup(my_setup_function, my_teardown_function)\ndef test_strings_a_3():\n print('test_strings_a_3 <============================ actual test code')\n assert multiply('a',3) == 'aaa'\n\n\nclass TestUM:\n\n def setup(self):\n print("TestUM:setup() before each test method")\n\n def teardown(self):\n print("TestUM:teardown() after each test method")\n\n @classmethod\n def setup_class(cls):\n print("setup_class() before any methods in this class")\n\n @classmethod\n def teardown_class(cls):\n print("teardown_class() after any methods in this class")\n\n def test_numbers_5_6(self):\n print('test_numbers_5_6() <============================ actual test code')\n assert multiply(5,6) == 30\n\n def test_strings_b_2(self):\n print('test_strings_b_2() <============================ actual test code')\n assert multiply('b',2) == 'bb'</code></pre></div><p>Result:</p>\n<div class=\"highlight\"><pre><code>$ nosetests -s test_um_nose_fixtures.py\n\nsetup_module before anything in this file\nsetup_class() before any methods in this class\nTestUM:setup() before each test method\ntest_numbers_5_6() <============================ actual test code\nTestUM:teardown() after each test method\n.TestUM:setup() before each test method\ntest_strings_b_2() <============================ actual test code\nTestUM:teardown() after each test method\n.teardown_class() after any methods in this class\nmy_setup_function\ntest_numbers_3_4 <============================ actual test code\nmy_teardown_function\n.my_setup_function\ntest_strings_a_3 <============================ actual test code\nmy_teardown_function\n.teardown_module after everything in this file\n\n----------------------------------------------------------------------\nRan 4 tests in 0.002s\n\nOK</code></pre></div><h4>pytest</h4>\n<p>First, you have to install pytest:</p>\n<div class=\"highlight\"><pre><code>pip install pytest</code></pre></div><p>Unit test counterpart code:</p>\n<div class=\"highlight\"><pre><code>import unittest\nfrom unnecessary_math import multiply\n\nclass TestUM(unittest.TestCase):\n\n def test_numbers_3_4(self):\n self.assertEqual( multiply(3,4), 12)</code></pre></div><p>Pytest version:</p>\n<div class=\"highlight\"><pre><code>from unnecessary_math import multiply\n\ndef test_numbers_3_4():\n assert( multiply(3,4) == 12 )</code></pre></div><p>There is no need to import unnittest.</p>\n<p>There is no need to derive from TestCase.</p>\n<p>There is no need to for special self.assertEqual(), since we can use Python’s built in assert statement.</p>\n<p><strong>test_um_pytest.py</strong></p>\n<div class=\"highlight\"><pre><code>from unnecessary_math import multiply\n\ndef test_numbers_3_4():\n assert multiply(3,4) == 12 \n\ndef test_strings_a_3():\n assert multiply('a',3) == 'aaa'</code></pre></div><p>Run tests:</p>\n<div class=\"highlight\"><pre><code>python -m pytest -v test_um_pytest.py\npy.test -v test_um_pytest.py</code></pre></div><p>Result:</p>\n<div class=\"highlight\"><pre><code>py.test -v test_um_pytest.py\n============================================================================================================ test session starts =============================================================================================================\nplatform darwin -- Python 3.7.0, pytest-3.8.0, py-1.6.0, pluggy-0.7.1 -- /Users/jasiplum/Development/Projects/Tieto/Python/naucse/venv/bin/python\ncachedir: .pytest_cache\nrootdir: /Users/jasiplum/Development/Projects/Tieto/Python/naucse, inifile:\ncollected 2 items\n\ntest_um_pytest.py::test_numbers_3_4 PASSED [ 50%]\ntest_um_pytest.py::test_strings_a_3 PASSED [100%]\n\n========================================================================================================== 2 passed in 0.07 seconds ==========================================================================================================</code></pre></div><h4>pytest setup and teardown</h4>\n<p>Although unittest does allow us to have setup and teardown, pytest extends this quite a bit.\nWe can add specific code to run:</p>\n<ul>\n<li>at the beginning and end of a module of test code (setup_module/teardown_module)</li>\n<li>at the beginning and end of a class of test methods (setup_class/teardown_class)</li>\n<li>alternate style of the class level fixtures (setup/teardown)</li>\n<li>before and after a test function call (setup_function/teardown_function)</li>\n<li>before and after a test method call (setup_method/teardown_method)</li>\n</ul>\n<p>Full example <strong>test_um_pytest2.py</strong>:</p>\n<div class=\"highlight\"><pre><code>from unnecessary_math import multiply\n\ndef setup_module(module):\n print("setup_module module:%s" % module.__name__)\n\ndef teardown_module(module):\n print("teardown_module module:%s" % module.__name__)\n\ndef setup_function(function):\n print("setup_function function:%s" % function.__name__)\n\ndef teardown_function(function):\n print("teardown_function function:%s" % function.__name__)\n\ndef test_numbers_3_4():\n print('test_numbers_3_4 <============================ actual test code')\n assert multiply(3,4) == 12\n\ndef test_strings_a_3():\n print('test_strings_a_3 <============================ actual test code')\n assert multiply('a',3) == 'aaa'\n\n\nclass TestUM:\n\n def setup(self):\n print("setup class:TestStuff")\n\n def teardown(self):\n print("teardown class:TestStuff")\n\n def setup_class(cls):\n print("setup_class class:%s" % cls.__name__)\n\n def teardown_class(cls):\n print("teardown_class class:%s" % cls.__name__)\n\n def setup_method(self, method):\n print("setup_method method:%s" % method.__name__)\n\n def teardown_method(self, method):\n print("teardown_method method:%s" % method.__name__)\n\n def test_numbers_5_6(self):\n print('test_numbers_5_6 <============================ actual test code')\n assert multiply(5,6) == 30\n\n def test_strings_b_2(self):\n print('test_strings_b_2 <============================ actual test code')\n assert multiply('b',2) == 'bb'\n``\n\nExpected result:</code></pre></div><p>$ py.test -v test_um_pytest2.py\n============================================================================================================ test session starts =============================================================================================================\nplatform darwin -- Python 3.7.0, pytest-3.8.0, py-1.6.0, pluggy-0.7.1 -- /Users/jasiplum/Development/Projects/Tieto/Python/naucse/venv/bin/python\ncachedir: .pytest_cache\nrootdir: /Users/jasiplum/Development/Projects/Tieto/Python/naucse, inifile:\ncollected 4 items</p>\n<p>test_um_pytest2.py::test_numbers_3_4 PASSED [ 25%]\ntest_um_pytest2.py::test_strings_a_3 PASSED [ 50%]\ntest_um_pytest2.py::TestUM::test_numbers_5_6 PASSED [ 75%]\ntest_um_pytest2.py::TestUM::test_strings_b_2 PASSED [100%]</p>\n<p>========================================================================================================== 4 passed in 0.08 seconds ==========================================================================================================</p>\n<div class=\"highlight\"><pre><code>\nYou can also run unittests and doctest with pytest.\n\n\n### Other testing tools\n\n#### Unit tests\n\npytest-cov: display the test coverage of your project\n\npytest-flake8: linter to make sure that your code is following the PEP8 style\n\nTox: http://tox.readthedocs.io - Tox can automate the creation of separate environments to run your tests.\n\n#### Functional tests\n\nWebTest: http://webtest.readthedocs.io\n\n#### Load tests\n\nApache Bench\n\nBoom: https://github.com/tarekziade/boom\n\nMolotov: https://github.com/tarekziade/molotov\n\nlocust.io: http://docs.locust.io\n\n#### End-to-end tests\n\nSelenium: http://docs.seleniumhq.org/\n\n\n#### Tests coverage\n\ncoverage: https://coverage.readthedocs.io\n\n### Developer documentation\n\nSphinx: http://www.sphinx-doc.org/\n\nThe following is a full example of a project documentation using Sphinx:</code></pre></div><h1>Myservice</h1>\n<p><strong>myservice</strong> is a simple JSON Flask application that uses <strong>Flakon</strong>.</p>\n<p>The application is created with :func:<code>flakon.create_app</code>: \n.. literalinclude:: ../../myservice/app.py</p>\n<p>The :file:<code>settings.ini</code> file which is passed to :func:<code>create_app</code>\ncontains options for running the Flask app, like the DEBUG flag: \n.. literalinclude:: ../../myservice/settings.ini\n :language: ini</p>\n<p>Blueprint are imported from :mod:<code>myservice.views</code> and one \nBlueprint and view example was provided in :file:<code>myservice/views/home.py</code>:</p>\n<p>.. literalinclude:: ../../myservice/views/home.py \n :name: home.py \n :emphasize-lines: 13</p>\n<p>Views can return simple mappings (as highlighted in the example above), \nin that case, they will be converted into a JSON response. \n```</p>\n<p><span class=\"figure\"><a href=\"/2019/tieto-ostrava-jaro/beginners/tieto-testing/static/sphinx.png\"><img src=\"/2019/tieto-ostrava-jaro/beginners/tieto-testing/static/sphinx.png\" alt=\"Sphinx\"></a></span></p>\n<h3>Homework</h3>\n<p>Write simple production function and their unit tests with following test cases:</p>\n<ul>\n<li>Function leap_year()</li>\n<li>Function leap_year will return True/False based on status of year, if is leap or not</li>\n<li>Returns false for not divisible by 4</li>\n<li>Returns true for divisible by 4 but not 100 and 400</li>\n<li>Returns false for divisible by 4 but is divisible by 100 but not 400</li>\n<li>Returns true for divisible by 4, divisible by 100 and divisible by 400</li>\n</ul>\n<p>Use PyTest framework.</p>\n\n\n " } } }