没有项目描述
nose-knows的Python项目详细描述
nose knows是一个nose插件,用于确定应该进行哪些单元测试 修改代码后运行。它的工作原理是在运行单元时跟踪代码 测试,并创建可供以后使用的输出文件。
安装
您可以通过pip或easy-install安装nose knows:
pip install nose-knows
或者您可以下载latest development version,它可以 包含新功能。
使用nose knows
nose knows可以在输入或输出模式下调用。在输出模式下 (--knows-out)它将生成包含映射的.knows文件 从代码树中的文件到运行它的单元测试集。输入 模式下,它使用.knows文件根据 您传入的文件。注意:这里,$BASE_DIR是基本项目的名称 目录,而不是它的(直接/相对)路径。它用来计算 重命名输出文件中的文件名以使其更可移植。
创建.knows文件:
eyal-01575:src eyal$ nosetests --with-knows --knows-dir=$BASE_DIR --knows-out ..................................................................... ---------------------------------------------------------------------- Ran 62 tests in 0.444s OK
.knows文件现在包含以下内容:
warehouse/src/load_data/sql_utils/checkpoints.py: src.tests.test_load_data_statements:TestSQLStatement.test_finalize src.tests.test_load_data_checkpoints:TestCheckpoints.test_checkpoint_finalize_with_delete src.tests.test_load_data_checkpoints:TestCheckpoints.test_checkpoint_finalize src.tests.test_load_data_checkpoints:TestCheckpoints.test_checkpoint_with_previous_checkin src.tests.test_load_data_checkpoints:TestCheckpoints.test_checkpoint src.tests.test_load_data_statements:TestSQLStatement.test_to_sql_import src.tests.test_load_data_statements:TestSQLStatement.test_to_sql_schema_update
现在可以在输入模式下运行nose knows,传入 load_data/sql_utils/checkpoints.py:
eyal-01575:src eyal$ nosetests --with-knows --knows-dir=$BASE_DIR load_data/sql_utils/checkpoints.py ....... ---------------------------------------------------------------------- Ran 7 tests in 0.003s OK
在这一点上,py.test也有(实验性的)支持。你可以 通过:
生成.knows文件eyal-01575:src eyal$ py.test --with-knows --knows-dir=$BASE_DIR --knows-out ===================== test session starts ====================== platform darwin -- Python 2.7.1 -- pytest-2.3.4 plugins: nose-knows collected 62 items tests/test_load_data_checkpoints.py .... tests/test_load_data_from_mysql.py .. tests/test_load_data_statements.py ..... tests/test_process_data_denormalize.py ........ tests/test_process_data_mapping.py ..... tests/test_transform_data_daemon.py . tests/test_transform_data_table_follower.py ................. tests/test_transformers/test_avg_data.py .. tests/test_transformers/test_count.py ... tests/test_transformers/test_join.py .... tests/test_transformers/test_json_data.py ..... tests/test_transformers/test_min_data.py .. tests/test_transformers/test_std_data.py .. tests/test_transformers/test_sum_data.py .. ================== 62 passed in 2.18 seconds ===================
并有选择地运行特定的单元测试,如so:
eyal-01575:src eyal$ py.test --with-knows --knows-dir=$BASE_DIR load_data/sql_utils/checkpoints.py ===================== test session starts ====================== platform darwin -- Python 2.7.1 -- pytest-2.3.4 plugins: nose-knows collected 62 items tests/test_load_data_checkpoints.py .... tests/test_load_data_statements.py ... =================== 7 passed in 0.30 seconds ===================
这里的最佳实践是让jenkins这样的系统运行单元测试套件 偶尔创建这个地图(我们每天运行),然后 创建bash函数/脚本从jenkins下载knows输出文件 并对提交中更改的文件集运行它。我们的看起来是:
function grab_latest_knows_output() { NOW=`date +%s` if [ ! -f $KNOWS_FILE_TMP ] ; then curl --compressed $KNOWS_FILE_URL > $KNOWS_FILE_TMP else KNOWS_FILE_AGE=`stat -c %Y $KNOWS_FILE_TMP` if [ `expr $NOW - $KNOWS_FILE_AGE` -gt "86400" ] ; then curl --compressed $KNOWS_FILE_URL > $KNOWS_FILE_TMP else echo "Using latest knows output file." fi fi } function test_changed() { grab_latest_knows_output nosetests $KNOWS_FLAGS `git diff --name-only --cached origin | xargs` } function run_tests_for() { grab_latest_knows_output nosetests $KNOWS_FLAGS $@ }
许可证
nose知道是2013年eventbrite和贡献者的版权,由 在BSD样式许可下提供;有关详细信息,请参阅许可。
新闻
0.1.2
增加了对基于nose的非unittest测试的支持。
0.1.1
小错误修复,使nose插件对错误的测试名称更有弹性。
0.1
发布日期:2012年4月2日
- nose knows的初始写入,包括对nose的支持和实验 支持py.test