python command line execution unit testing unittest

unittest Unit testing is an important part in development, python is also more convenient

Environment to build

For custom package package project, you need to specify package paths, there are two ways

  1. When using sys.path, but this requires that each run of other documents to be executed once

    sys.path本身是多个地址的列表。
    sys.path.append():添加一个地址
    sys.path += [directory's list] :添加多个地址(或者也可以用sys.path.extend())
    sys.path.remove() 去掉地址
  2. PYTHONPATH variable setting condition
    to add the path to the package PYTHONPATH

  3. As for how the custom namespace package, which involves the python, not expanded
    https://www.python.org/dev/peps/pep-0420/

Test execution

python -m unittest MODULE/CLASS/FUNCTION 

Since unittest files are beginning to test_, so the module is part of the name test_ removed

If you do not know which use cases, you can find -v

python -m unittest -v

Performance Testing

Sometimes, we not only ensure the accuracy of the unit test code, but also to locate perf penalty by cProfile, that is, to locate where the performance loss
using cPerf can check performance

python -m cPerf 

Not only that, you can also count perf by such a large tool such as kcachegrind

to sum up

Visible python is very convenient

Guess you like

Origin www.cnblogs.com/hustcpp/p/12431074.html