列出测试用例和测试的shell自动完成助手
django-test-autocomplete的Python项目详细描述
此包提供了在项目中运行特定测试的有用方法。
通过在内部提供自动完成功能,加快对要运行的测试的调用 测试模块,列出其测试用例以及每个测试用例中的测试。
第一个版本是概念的证明,在“未来特性”部分 有一个列表列出了下一个版本可能考虑的改进。
它是如何工作的
为了进行非侵入性安装,而不是耦合此 使用django提供的自动完成功能,我们创建了一个代理命令 命名为“djntest”,其作用是将每个调用重定向到自身 “python manage.py测试”。
稍后,我们定义了这个新命令的自定义自动完成。 自动完成是用bash代码的轻量级层定义的,它是 每次用户触发自动完成时调用(通常通过点击 <;tab>;键)。根据提供的参数,bash层决定调用 helper python脚本get_testcases.py反过来读取提供的.py 文件,并使用ast模块解析它。
如何使用
位于Django项目的根目录中,键入:
$ djntest books_application/tests/test_book_creation.py:<TAB>
- 将以标准bash方式列出该文件中定义的所有类,即:
- 如果只有一个选项,它将自动完成
- 如果给定时间内的所有选项都具有相同的前缀,则它将自动完成
- 如果开始在冒号后面键入某个测试用例的名称,请单击<;tab>; 再次将筛选仅与您所写内容匹配的报价
在一个测试用例名之后,如果您有一个点并像这样触发自动完成功能
$ djntest books_application/tests/test_book_creation.py:TestStore.<TAB>
您将看到该类中定义的以名称开头的所有函数 使用“test”和所有常用的bash自动完成功能。
免责声明注释:
- This autocompleter only facilitates the way of invoking the command for your running tests. Nothing related with PYTHONPATH is done here.
- If your test runner does not support be called with individual tests modules (like django-nose does), then you will have to wait for 0.2 release in order to enjoy this package.
安装说明:
要安装此软件包,您需要执行两个步骤:
首先安装脚本
$ sudo pip install django-test-autocomplete
或者,也可以从源发行版安装它: 取出皮球并运行
$ python setup.py install
2.为了启用bash自动完成,您需要查找 位于源发行版中的script djntest.sh及更高版本 执行下列操作之一:
inside your $HOME/.bashrc adding a line like this:
source path/to/djntest.sh
将文件复制到bash配置文件夹中,如下所示:
$ copy path/to/djntest.sh /etc/bash_completion.d/
然后重新启动bash会话。
可以找到djntest.sh文件:
- on the source distribution
- on /etc/django-test-autocomplete/djntest.sh or if working with virtualenv, on $VIRTUAL_ENV/etc/django-test-autocomplete/djntest.sh
- https://raw.github.com/machinalis/django-test-autocomplete/master/djntest.sh
额外: 用于运行内部包测试(如果要尝试自定义 或者扩展这个包)您必须首先安装模拟包。
未来功能:
- Improve the python file parsing (done now with ast) for:
- Detecting if defined classes are TestCases or not
- Detect tests defined on parent TestCases
- Clear integration with the usual way of running django tests (ie, avoid the need of “proxy” command djntest)
- Try it out with not-only django projects
- Support for some other shells (zsh will probably be the next one)
测试时间:
- GNU bash, version 4.1.5+
- bash completion 1.1+
- Django 1.3+
- I’m using it together with django-nose without problems. I see no reason for have it not working without nose.