这两种测试方法的区别

时间:2015-07-01 03:58:54

标签: python unit-testing testing

为了测试Python库,我可以做任何一个

python setup.py install
python setup.py test

python setup.py build
python setup.py test

我更喜欢采用后一种方式。如果不去第一个,我会缺少什么?

编辑:如何测试已安装的代码?后一种方式不是那样做的。

注意:我没有先选择,因为在这种情况下,我觉得Travis-CI在许可级别出现问题。 这是错误日志

======================================================================
ERROR: Failure: OSError ([Errno 20] Not a directory: '/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/networkx_metis-1.0-py2.7-linux-x86_64.egg/networkx')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/nose/loader.py", line 414, in loadTestsFromName
    addr.filename, addr.module)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/nose/importer.py", line 86, in importFromDir
    if (self.sameModule(old, filename)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/nose/importer.py", line 131, in sameModule
    if _samefile(mod_path, new_path):
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/posixpath.py", line 162, in samefile
    s1 = os.stat(f1)
OSError: [Errno 20] Not a directory: '/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/networkx_metis-1.0-py2.7-linux-x86_64.egg/networkx'
----------------------------------------------------------------------
Ran 1 test in 0.314s
FAILED (errors=1)
The command "python setup.py test" exited with 1

1 个答案:

答案 0 :(得分:0)

无法对Travis-CI发表评论,但实际建议的方法没有差异。

python setup.py install内部附有python setup.py build。就这样, install 创建了一个.egg文件,并将其复制到系统的dist-packagessite-packages

关于测试,两种方法之间没有这种差异。