Skip to main content

A nose plugin to detect tests making http calls.

Project description

A nose and pytest plugin that can detect tests making external http calls. With nose, it adds a single artificial failure with all the results:

$ 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)

With pytest, failures are added to individual tests:

$ 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

Localhost is automatically ignored. To ignore other hosts, use the –vcr-ignore-host option, which takes a comma-delimited list:

$ 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

Under the hood, this wraps every test in a separate VCR.py cassette. Since VCR.py’s hooks are in the stdlib, this approach won’t detect requests made with clients like PycURL.

History

1.1.0

released 2018-12-18

  • add pytest support

1.0.0

released 2018-09-12

  • breaking: ignore host flag now accepts comma-separated values rather than being provided multiple times

0.2.0

released 2017-08-15

  • add –vcr-ignore-host option to ignore custom hosts

0.1.3

released 2015-10-16

  • python 3 support

0.1.1

released 2014-11-24

  • initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nose-detecthttp-1.1.0.tar.gz (5.8 kB view details)

Uploaded Source

File details

Details for the file nose-detecthttp-1.1.0.tar.gz.

File metadata

  • Download URL: nose-detecthttp-1.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/2.7

File hashes

Hashes for nose-detecthttp-1.1.0.tar.gz
Algorithm Hash digest
SHA256 b895167d8050871577e1a4ef41e4290b4dc18a2b1178ae87ace3710cb641657d
MD5 b93ed7d4fc6fd656ca3d2d2ebe70a21b
BLAKE2b-256 848c42a20bc30339fe3d9dbd6957145577ea6274bf7a16ac176a2abfac9e2715

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page