学习Django官网上自带的tests例子
1.首先下载https://github.com/django/django
需要注意的是Django1.11.x版本目前支持Python2.7和3.x;而Django2.x版本系列的只支持Python3.x系列了。由于我的Python环境是2.7,因此git clone下来时候需要版本git checkout到1.11.x。
2.照着官网tests目录下readme.rst的文档进行按步骤操作:
(env) MacBook-Pro:django.git zhengguangguo$ cd tests/
(env) MacBook-Pro:tests zhengguangguo$ ls README.rst
README.rst
(env) MacBook-Pro:tests zhengguangguo$
(env) MacBook-Pro:tests zhengguangguo$ pwd
/Users/zhengguangguo/develop/python/django/django.git/tests
(env) MacBook-Pro:tests zhengguangguo$
(env) MacBook-Pro:tests zhengguangguo$ cat README.rst
To run the test suite, first, create and activate a virtual environment. Then
install some requirements and run the tests::
# Setup the virtual environment
$ virtualenv env
$ source env/bin/activate
$ cd tests
$ pip install -e ..
$ pip install -r requirements/py3.txt # or py2.txt
$ ./runtests.py
For more information about the test suite, see
https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/.
(env) MacBook-Pro:tests zhengguangguo$
需要注意的步骤有:
$ virtualenv env
$ source env/bin/activate
$ pip install -r requirements/py2.txt
3.打开Pycharm并将Django.git导入,同时新建一个Python解释器
4.设置pycharm的edit configurations
5.运行debug调试按钮,断点就会进入many_to_one下面的tests.py中。
附录:
1.新建Python项目为避免依赖,需要隔离环境:
mkdir ~/scrapers/zipru
cd ~/scrapers/zipru
virtualenv env
. env/bin/activate
pip install scrapy
参考自《爬虫进阶:反反爬虫技巧》