Testing with PyTest

In fact, poetry even generates a test function for us, though it doesn't test our code; instead, it checks the version. Take a look at the code here:

from wikiwwii import __version__

def test_version():
assert __version__ == '0.1.0'

Here, two things are worth discussing. First, as you can see, the test is just a function with the word "test" in its name. Having this word is necessary—this is the way pytest finds all the tests. Second, each test results in one or a few assert statements. To pass the test, assert should not raise any issues. That's all the basics of test development. 

Now let's run this existing test; generally speaking, all we need is to type pytest tests on the command line. With poetry, however, we have a hidden virtual environment intended for development, so that's where we should run our tests; for that, type poetry run pytest tests. If everything is okay, pytest should print out a small report with the version of Python, pytest, the package, and a description of the tests, as follows:

>>> poetry run pytest tests
========================= test session starts =========================================
platform darwin -- Python 3.7.1, pytest-3.10.1, py-1.8.0, pluggy-0.12.0
rootdir: /Users/philippk/Dropbox/personal_projects/wikiwwii, inifile:
collected 1 item

tests/test_wikiwwii.py . [100%]

============================ 1 passed in 0.02 seconds =====================================

Yay! This test has passed.

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

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