跟我學python(5)---自動化測試(一個32銷售員的自學之路)
今天是學習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
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
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 自動構建生成,後者是自己生成。
兩者區別是?
分別建立檔案,測試就好了。
第一個專案骨架檔案: