Python单元测试忽略numpy
我正在用unittest编写python测试,并使用命令行运行测试
nosetests --with-coverage -x
当我在我的一个测试中包含numpy时,它也会尝试测试numpy包。 示例输出:
...
Name Stmts Miss Cover Missing
-------------------------------------------------------------
CLOCK 39 33 15% 3, 7-13, 17, 20-25, 28-47
LFU 42 1 98% 52
LRU 95 9 91% 12, 64, 68, 101, 115-118, 131
LRU10 54 1 98% 68
LRU3 54 1 98% 68
argparse 1177 1177 0% 3-2361
cache 86 33 62% 36-47, 86-89, 95-116
common 87 54 38% 17, 20, 23, 28, 31-32, 35-36, 39, 42, 46, 48, 50, 52, 54, 57-64, 67-68, 72-89, 95-96, 102-107, 112-118, 123
ctypes 341 341 0% 4-555
ctypes._endian 35 35 0% 4-64
numpy 56 56 0% 107-197
numpy.__config__ 27 27 0% 3-32
numpy._import_tools 224 224 0% 1-348
numpy.add_newdocs 275 275 0% 11-7459
numpy.compat 8 8 0% 11-20
numpy.compat._inspect 106 106 0% 8-221
numpy.compat.py3k 57 57 0% 5-89
numpy.core 56 56 0% 1-74
numpy.core._internal 350 350 0% 7-570
numpy.core._methods 72 72 0% 6-130
numpy.core.arrayprint 354 354 0% 6-752
numpy.core.defchararray 364 364 0% 18-2686
numpy.core.fromnumeric 310 310 0% 4-2918
numpy.core.function_base 24 24 0% 1-173
numpy.core.getlimits 132 132 0% 4-306
numpy.core.info 3 3 0% 84-87
numpy.core.machar 186 186 0% 8-338
numpy.core.memmap 83 83 0% 1-305
numpy.core.numeric 523 523 0% 1-2730
numpy.core.numerictypes 381 381 0% 83-1035
numpy.core.records 356 356 0% 37-808
numpy.core.shape_base 50 50 0% 1-277
numpy.ctypeslib 187 187 0% 52-426
numpy.fft 7 7 0% 1-11
numpy.fft.fftpack 109 109 0% 33-1119
numpy.fft.helper 51 51 0% 5-223
numpy.fft.info 2 2 0% 177-179
numpy.lib 38 38 0% 1-45
numpy.lib._datasource 178 178 0% 34-656
numpy.lib._iotools 372 372 0% 4-874
numpy.lib.arraypad 383 383 0% 6-1469
numpy.lib.arraysetops 98 98 0% 27-450
numpy.lib.arrayterator 72 72 0% 10-224
numpy.lib.financial 112 112 0% 11-735
numpy.lib.format 178 178 0% 137-614
numpy.lib.function_base 889 889 0% 1-3555
numpy.lib.index_tricks 250 250 0% 1-849
numpy.lib.info 3 3 0% 148-151
numpy.lib.nanfunctions 138 138 0% 17-838
numpy.lib.npyio 729 729 0% 1-1899
numpy.lib.polynomial 386 386 0% 5-1266
numpy.lib.scimath 55 55 0% 18-560
numpy.lib.shape_base 200 200 0% 1-834
numpy.lib.stride_tricks 48 48 0% 8-121
numpy.lib.twodim_base 116 116 0% 4-929
numpy.lib.type_check 104 104 0% 4-605
numpy.lib.ufunclike 23 23 0% 6-177
numpy.lib.utils 517 517 0% 1-1134
numpy.linalg 6 6 0% 45-54
numpy.linalg.info 2 2 0% 35-37
numpy.linalg.linalg 530 530 0% 11-2131
numpy.ma 15 15 0% 39-58
numpy.ma.core 2324 2324 0% 23-7243
numpy.ma.extras 610 610 0% 11-1885
numpy.matrixlib 6 6 0% 4-12
numpy.matrixlib.defmatrix 286 286 0% 1-1094
numpy.polynomial 11 11 0% 16-29
numpy.polynomial.chebyshev 432 432 0% 88-2015
numpy.polynomial.hermite 382 382 0% 60-1750
numpy.polynomial.hermite_e 379 379 0% 60-1746
numpy.polynomial.laguerre 379 379 0% 60-1742
numpy.polynomial.legendre 386 386 0% 84-1768
numpy.polynomial.polynomial 302 302 0% 56-1493
numpy.polynomial.polytemplate 4 4 0% 12-17
numpy.polynomial.polyutils 67 67 0% 34-384
numpy.random 13 13 0% 89-114
numpy.random.info 3 3 0% 85-89
numpy.version 7 7 0% 3-10
statistics 19 2 89% 24-25
statistics.countingghost 84 44 48% 43-60, 66-69, 75-80, 83-89, 93-104, 107, 110-113
statistics.rounder 89 17 81% 29, 40, 70-83, 112-113
-------------------------------------------------------------
TOTAL 17686 17145 3%
----------------------------------------------------------------------
Ran 3 tests in 3.279s
OK
如何正确地忽略-I -m或-e参数的numpy测试? 我可以管这个grep -v numpy但这并不酷。
有一个鼻子插件专门用于任务 - 鼻子排除:
nose-exclude是一个鼻插件,允许您轻松指定要从测试中排除的目录。
另一个选项是在.coveragerc
文件中指定omit
配置参数:
省略(多字符串):文件名模式的列表,这些文件不在测量或报告之列。
另请参阅:如何使用nosetests从python coverage报告中排除模拟包
当您使用--cover-package
标志调用nose时,您还可以指定要运行哪个包的测试。
例如
nosetests --with-coverage --cover-package=the-name-of-your-package -x
链接地址: http://www.djcxy.com/p/78671.html