python nose setuptools 快速入門

安裝nose

pip3 install nose

安裝setuptools

 pip3 install setuptools

 

簡單項目測試信息如下

ks@ubuntu:/work/project$ ls ndemotest -1R
ndemotest:
setup.py
tests

ndemotest/tests:
NAME_test.py
__pycache__

setup.py

from distutils.command.install_data import install_data

packages = ['tests', ]
scripts = ['tests/NAME_test.py',]
cmdclasses = {'install_data': install_data}
#data_files = [('etc', ['etc/myproject.cfg'])]

setup_args = {
    'name': 'myproject',
    'version': '0.1',
    'packages': packages,
    'cmdclass': cmdclasses,
    'data_files': "",
    'scripts': scripts,
#    'include_package_data': True,
    'test_suite': 'nose.collector'
}

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup

setup(**setup_args)

NAME_test.py

from nose import tools

class Testnametest:

    def __init__(self):
        pass

    def setup(self):
        print("start!")

    def teardown(self):
        print("End....")

    def testfunc1(self):
        a = 1
        b = 1
        tools.ok_(a == b,"通過")
        print("case1通過")

    def testfunc2(self):
        a = 2
        b = 1
        tools.ok_(a == b,"失敗")
        print("case2失敗")

項目測試結果

ks@ubuntu:/work/project/ndemotest$ python3 setup.py test
running test
WARNING: Testing via this command is deprecated and will be removed in a future version. Users looking for a generic test entry point independent of test runner are encouraged to use tox.
running egg_info
creating myproject.egg-info
writing myproject.egg-info/PKG-INFO
writing dependency_links to myproject.egg-info/dependency_links.txt
writing top-level names to myproject.egg-info/top_level.txt
writing manifest file 'myproject.egg-info/SOURCES.txt'
package init file 'tests/__init__.py' not found (or not a regular file)
reading manifest file 'myproject.egg-info/SOURCES.txt'
writing manifest file 'myproject.egg-info/SOURCES.txt'
running build_ext
NAME_test.Testnametest.testfunc1 ... ok
NAME_test.Testnametest.testfunc2 ... FAIL

======================================================================
FAIL: NAME_test.Testnametest.testfunc2
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ksuser/.local/lib/python3.6/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/work/project/ndemotest/tests/NAME_test.py", line 23, in testfunc2
    tools.ok_(a == b,"失敗")
AssertionError: 失敗
-------------------- >> begin captured stdout << ---------------------
start!
End....

--------------------- >> end captured stdout << ----------------------

----------------------------------------------------------------------
Ran 2 tests in 0.002s

FAILED (failures=1)
Test failed: <unittest.runner.TextTestResult run=2 errors=0 failures=1>
error: Test failed: <unittest.runner.TextTestResult run=2 errors=0 failures=1>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章