今天是学习python ,做博客的第五天,比较疲倦。 但是依旧要就绪哦。
知识点:
- nose是什么?
- pypi的知识
困惑:
自动化测试:
今天要要学习的是python 第三方包,
nose:
# 一、 安装:
sudo pip install nose
使用:
还记得上节课的时候,我们提出的测试问题吗? 终端需要做不断测试吗? 如果是这样, 不是很浪费时间, 还有一次性搞完, 要不,一次测试不完,下次继续,不过python是有这样方法的。
使用第三方库 ***nose***
功能:
第三方库, 看看pypi官方,或者作者官方说明吧。
>On most UNIX-like systems, you’ll probably need to run these commands as root or using sudo.
Install nose using setuptools/distribute:
easy_install nose
Or pip:
pip install nose
以上[说明]来自(http://nose.readthedocs.org/en/latest/),强烈建议去看官方文档,在官方文档中,我们会发现,这么一句话:
This will install the nose libraries, as well as the nosetests script, which you can use to automatically discover and run tests. Now you can run tests for your project: cd path/to/project
nosetests
1:证明了撒?
说明了安装nose,会自动安装nosetest这个脚本, 这脚本作用就是测试,继续看nosetest [官方说明](http://nose.readthedocs.org/en/latest/usage.html):
2: 暂时不看英文了。
基础知识不是很好,这个也不是特别需要学习的, 。
# 使用。
1、测试自己安装的printlist模块
```python
import printlist
```
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named printlist
发现错误,但是自己pip freeze
printlist==1.0.0
是有的,这是怎么回事?
(不清楚,暂时v2去问了, 学习也必须学问求助,看看别的)
看了看,大致的原因,python3 是可以导入的,而python2无法导入, pip uninstall printlist ,发现了。
Uninstalling printlist-1.0.0:
/Library/Python/2.7/site-packages/printlist-1.0.0- py2.7.egg
居然安装在python2.7下面, 这是为撒呢????)
卸载重新安装:这回好好看看
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: ‘author_mail’
warnings.warn(msg)
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: ‘py_moudle’
warnings.warn(msg)
running install
Checking .pth file support in /Library/Python/2.7/site-packages/
/usr/bin/python -E -c pass
TEST PASSED: /Library/Python/2.7/site-packages/ appears to support .pth files
running bdist_egg
running egg_info
writing printlist.egg-info/PKG-INFO
writing top-level names to printlist.egg-info/top_level.txt
writing dependency_links to printlist.egg-info/dependency_links.txt
reading manifest file ‘printlist.egg-info/SOURCES.txt’
writing manifest file ‘printlist.egg-info/SOURCES.txt’
installing library code to build/bdist.macosx-10.10-intel/egg
running install_lib
warning: install_lib: ‘build/lib’ does not exist – no Python modules to install
creating build/bdist.macosx-10.10-intel/egg
creating build/bdist.macosx-10.10-intel/egg/EGG-INFO
copying printlist.egg-info/.DS_Store -> build/bdist.macosx-10.10-intel/egg/EGG-INFO
copying printlist.egg-info/PKG-INFO -> build/bdist.macosx-10.10-intel/egg/EGG-INFO
copying printlist.egg-info/SOURCES.txt -> build/bdist.macosx-10.10-intel/egg/EGG-INFO
copying printlist.egg-info/dependency_links.txt -> build/bdist.macosx-10.10-intel/egg/EGG-INFO
copying printlist.egg-info/top_level.txt -> build/bdist.macosx-10.10-intel/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents…
creating ‘dist/printlist-1.0.0-py2.7.egg’ and adding ‘build/bdist.macosx-10.10-intel/egg’ to it
removing ‘build/bdist.macosx-10.10-intel/egg’ (and everything under it)
Processing printlist-1.0.0-py2.7.egg
Copying printlist-1.0.0-py2.7.egg to /Library/Python/2.7/site-packages
Adding printlist 1.0.0 to easy-install.pth file
Installed /Library/Python/2.7/site-packages/printlist-1.0.0-py2.7.egg
Processing dependencies for printlist==1.0.0
Finished processing dependencies for printlist==1.0.0
这一回我安装成功了,在python2也可以导入,但是为什么之前是安装在python2.7里,不清楚. 思考一下, 在计算机我们应该想到的是,怎么解决问题,而不是为什么错了。看了看这几天的学习进度非常慢。
二、做测试的时候, 准备之前,发现啦几个问题。
> head first python
setup.py 模块.py
后面会自动生成几个文件夹,包括bin/bulid /dist/
printlist.egg-info
> learn python the hard way
setup.py docs test name tests
test/__init__.py
name_tests.py
name/__init__.py
前者是pip 自动构建生成,后者是自己生成。
两者区别是?
分别建立文件,测试就好了。
第一个项目骨架文件: