1. 安装virtualenv来设置虚拟环境

pip install virtualenv
    1. 创建.venvs文件夹,并在文件夹中装上虚拟环境

mkdir .venvs
virtualenv --system-site-packages .venvs/lpthw
    1. 激活虚拟环境

.\.venvs\lpthw\
    1. 安装nose

pip install nose
    1. 创建项目目录

mkdir projects
cd projects/
mkdir skeleton
cd skeleton
mkdir bin NAME tests docs
    1. 设置初始文件

new-item -type file NAME/__init__.py
new-item -type file tests/__init__.py
    1. 建立setup.py文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)
    1. 建立测试专用的骨架文件tests/NAME_test.py

1
2
3
4
5
6
7
8
9
10
11
12
13
# coding:utf-8
from nose.tools import *
 
import ex47
 
def setup():
    print("SETUP!")
 
def teardown():
    print("TEAR DOWN!")
 
def test_basic():
    print("I RAN!")
  1. 在tests/上一层目录运行nosetests


最终的目录结构:

skeleton/
     NAME/
         __init__.py
     bin/
     docs/
     setup.py
     tests/
         NAME_tests.py
         __init__.py

 

posted on   讲道理好嘛  阅读(35)  评论(0编辑  收藏  举报
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示