用于检测进行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

  • 初始版本

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
生成的代码为什么在无人机中使用Java是不安全的?   java实体继承和鉴别器列   java使用Struts 2中sj:datepicker的beforeShow事件   JavaMaven没有安装pom文件中的所有内容,导致“缺少必需的库”x124   java将自定义GIF从assets文件夹加载到recyclerview 安卓中   java实现稀疏数组   java在获得所需结果集后关闭连接对象   java在活动中将数组值添加到MClickListener()   java如何删除单元格工厂引用   java字符串。分号分隔   Java抽象和接口   java Intellij IDEA SLF4J:未能加载类“org.SLF4J.impl.StaticLoggerBinder”   java改造JsonArray recyclerview异常   JavaJUnit@Theory:有没有方法抛出有意义的异常?   如何在Java中将XML内容写入字符串?