2. Добавляем к python проекту тесты, покрытие и проверку чистоты кода (Adding tests, coverage a...).

Опубликовано: 22 Февраль 2026
на канале: Korolev Alexander
271
2

Adding tests, coverage and code style checker to python project.

46) .\mytestvenv\Scripts\deactivate
47) cd C:\work\Python\mypython
48) .\myvenv\Scripts\activate
49) in cmd "pip install tox"
49) create file "tox.ini" in "C:\work\Python\mypython"
50) add text in "tox.ini" file

[tox]
envlist = py38
skipsdist=true

[testenv]
commands = pytest
whitelist_externals = *

51) create folder "tests" in "C:\work\Python\mypython"
52) add file empty filr "__init__.py" in "C:\work\Python\mypython"
53) add file "test_hello.py" in "C:\work\Python\mypython\tests"
54) add code in "test_hello.py"

from src.myPyLib import SayHello


def test_SayHello():
assert SayHello("bb") == None

55) in cmd "tox"
56) pip install flake8
57) add to "tox.ini"

[flake8]
application_import_names = myPyLib, tests
max-line-length = 120
extend-ignore = E203,W503,E231,I201
exclude = myvenv, .tox, build, dist

58) in cmd "flake8"
59) pip install pytest-cov
60) pip install pytest-xdist
61) add to "tox.ini"

[pytest]
addopts = --cov=src.myPyLib --cov-append --cov-report term-missing

62) in cmd "tox"