-
安装virtualenv来设置虚拟环境
pip install virtualenv
-
创建.venvs文件夹,并在文件夹中装上虚拟环境
mkdir .venvs virtualenv --system-site-packages .venvs/lpthw
-
激活虚拟环境
..venvslpthw
-
安装nose
pip install nose
-
创建项目目录
mkdir projects cd projects/ mkdir skeleton cd skeleton mkdir bin NAME tests docs
-
设置初始文件
new-item -type file NAME/__init__.py new-item -type file tests/__init__.py
-
建立setup.py文件
try: from setuptools import setup except ImportError: from distutils.core import setup config = { 'description': 'My Project', 'author': 'My Name', 'url': 'URL to get it at.', 'download_url': 'Where to download it.', 'author_email': 'My email.', 'version': '0.1', 'install_requires': ['nose'], 'packages': ['NAME'], 'scripts': [], 'name': 'projectname' } setup(**config)
-
建立测试专用的骨架文件tests/NAME_test.py
# coding:utf-8 from nose.tools import * import ex47 def setup(): print("SETUP!") def teardown(): print("TEAR DOWN!") def test_basic(): print("I RAN!")
-
在tests/上一层目录运行nosetests
最终的目录结构:
skeleton/ NAME/ __init__.py bin/ docs/ setup.py tests/ NAME_tests.py __init__.py