Skip to main content

Pytest Plugin to disable socket calls during tests

Project description

See Build Status on Travis CI See Build Status on AppVeyor

A plugin to use with Pytest to disable socket calls during tests to ensure network calls are prevented.


This Pytest plugin was generated with Cookiecutter along with @hackebrot’s Cookiecutter-pytest-plugin template.

Features

  • Disables all network calls flowing throguh Python’s socket interface.

Requirements

Installation

You can install “pytest-socket” via pip from PyPI:

$ pip install pytest-socket

Usage

  • Run pytest, tests should fail on any access to socket or libraries using socket.

  • To enable specific tests use of socket, pass in the fixture to the test:

def test_explicitly_enable_socket(enable_socket):
    assert socket.socket(socket.AF_INET, socket.SOCK_STREAM)

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the MIT license, “pytest-socket” is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

References

This plugin came about due to the efforts by @hangtwenty solving a StackOverflow question, then converted into a pytest plugin by @miketheman.

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

pytest-socket-0.1.0.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file pytest-socket-0.1.0.tar.gz.

File metadata

  • Download URL: pytest-socket-0.1.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pytest-socket-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7089bb3418a1f41d9d29b18dbb65820c47bbe29254f6967bfb421d9ff42abf3d
MD5 59dd732a5c693d8ad5a5cea2cc5743e9
BLAKE2b-256 e4953cd275e3500ddfe5bf12fdf3c7ac75bd72204f76981797785ced00c477a5

See more details on using hashes here.

Supported by

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