用于检测进行http调用的测试的nose插件。
nose-detecthttp的Python项目详细描述
nose和pytest插件,可以检测进行外部http调用的测试。 使用鼻子,它会添加一个人工故障,所有结果如下:
$ nosetests -v --with-detecthttp example.py test_that_makes_request (example.ExampleTests) ... ok test_with_no_request (example.ExampleTests) ... ok ====================================================================== FAIL: Tests made external http calls ---------------------------------------------------------------------- - example.ExampleTests: test_that_makes_request: GET http://example.com/ ---------------------------------------------------------------------- Ran 2 tests in 0.063s FAILED (failures=1)
使用pytest,失败会添加到单个测试中:
$ pytest --with-detecthttp example.py ... item = <TestCaseFunction 'test_that_makes_request'> def pytest_runtest_teardown(item): # Note unmocked interactions collected during runtest_call. # This is raised here so that pytest doesn't mark it as an internal error. report = item.config._detecthttp_reports.pop(item.nodeid, None) if item.config._detecthttp_enabled and report: > raise report E UnmockedRequestsDetected: detecthttp noticed the following requests during this test: E GET http://example.com/ detecthttp/pytest.py:82: UnmockedRequestsDetected ...2 passed, 1 error in 0.35 seconds
本地主机将被自动忽略。
要忽略其他主机,请使用--vcr-ignore-host
选项,该选项采用逗号分隔的列表:
$ nosetests -v --with-detecthttp --vcr-ignore-host=example.com example.py test_that_makes_request (example.ExampleTests) ... ok test_with_no_request (example.ExampleTests) ... ok ---------------------------------------------------------------------- Ran 2 tests in 0.110s OK
在引擎盖下,这将每个测试包装在一个单独的VCR.py cassette中。 由于vcr.py的钩子在stdlib中,这种方法不会检测到像pycurl这样的客户机发出的请求。
历史记录
1.1.0
发布日期:2018-12-18
- 添加pytest支持
1.0.0
发布日期:2018-09-12
- 中断:忽略主机标志现在接受逗号分隔的值,而不是多次提供
0.2.0
发布日期:2017-08-15
- add–VCR ignore host选项忽略自定义主机
0.1.3
发布日期:2015-10-16
- python 3支持
0.1.1
发布日期:2014-11-24
- 初始版本