All Projects → miketheman → Pytest Socket

miketheman / Pytest Socket

Licence: mit
Pytest Plugin to disable socket calls during tests

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pytest Socket

Pysocket
PySocket ,一个通过猴子补丁(monkey patch)动态修改 socket 的项目。在不修改源码的情况下给 socket 增加一些诸如限制客户端数量、前置代理之类的功能。让我们将 Monkey Patch 进行到底吧!
Stars: ✭ 108 (-7.69%)
Mutual labels:  socket
Rails Testing Toolbox
🔧 Tools to help Rails developers test
Stars: ✭ 110 (-5.98%)
Mutual labels:  testing-tools
Goproxy
🔥 Proxy is a high performance HTTP(S) proxies, SOCKS5 proxies,WEBSOCKET, TCP, UDP proxy server implemented by golang. Now, it supports chain-style proxies,nat forwarding in different lan,TCP/UDP port forwarding, SSH forwarding.Proxy是golang实现的高性能http,https,websocket,tcp,socks5代理服务器,支持内网穿透,链式代理,通讯加密,智能HTTP,SOCKS5代理,黑白名单,限速,限流量,限连接数,跨平台,KCP支持,认证API。
Stars: ✭ 11,334 (+9587.18%)
Mutual labels:  socket
Mitm Scripts
🔄 A collection of mitmproxy inline scripts
Stars: ✭ 109 (-6.84%)
Mutual labels:  testing-tools
Acot
💎 Accessibility Testing Framework. More accessible web, all over the world.
Stars: ✭ 112 (-4.27%)
Mutual labels:  testing-tools
Graphql Live Query
Realtime GraphQL Live Queries with JavaScript
Stars: ✭ 112 (-4.27%)
Mutual labels:  socket
Swiftsocket
The easy way to use sockets on Apple platforms
Stars: ✭ 1,497 (+1179.49%)
Mutual labels:  socket
Gemini
💀💀💀[DEPRECATED] Use hermione
Stars: ✭ 1,505 (+1186.32%)
Mutual labels:  testing-tools
React Socket Io
A react provider for socket.io, http://socket.io/
Stars: ✭ 111 (-5.13%)
Mutual labels:  socket
Sample Chat Electron
Socket.io based chat server and clients, implemented in NodeJS and distributed to Windows and MacOS.
Stars: ✭ 116 (-0.85%)
Mutual labels:  socket
Gest
👨‍💻 A sensible GraphQL testing tool - test your GraphQL schema locally and in the cloud
Stars: ✭ 109 (-6.84%)
Mutual labels:  testing-tools
Faker
Go (Golang) Fake Data Generator for Struct
Stars: ✭ 1,698 (+1351.28%)
Mutual labels:  testing-tools
Fakedata
CLI utility for fake data generation
Stars: ✭ 114 (-2.56%)
Mutual labels:  testing-tools
Psrule
Validate infrastructure as code (IaC) and objects using PowerShell rules.
Stars: ✭ 107 (-8.55%)
Mutual labels:  testing-tools
Nose Timer
A timer plugin for nosetests (how much time does every test take?)
Stars: ✭ 116 (-0.85%)
Mutual labels:  testing-tools
Scala Pact
A Scala implementation of CDC using the Pact standard
Stars: ✭ 106 (-9.4%)
Mutual labels:  testing-tools
Tls Channel
A Java library that implements a ByteChannel interface over SSLEngine, enabling easy-to-use (socket-like) TLS for Java applications.
Stars: ✭ 113 (-3.42%)
Mutual labels:  socket
Mockey
Mockey is a tool for testing application interactions over http, with a focus on testing web services, specifically web or native applications that consume XML, JSON, and HTML. Mockey's purpose is to be a simple front end to writing mock-test-responses to the file system for persistence to git.
Stars: ✭ 117 (+0%)
Mutual labels:  testing-tools
Capybara discoball
Spin up an external server just for Capybara
Stars: ✭ 116 (-0.85%)
Mutual labels:  testing-tools
Kubernaut
Instant ephemeral Kubernetes clusters for development and testing
Stars: ✭ 115 (-1.71%)
Mutual labels:  testing-tools

============= pytest-socket

.. image:: https://img.shields.io/pypi/v/pytest-socket.svg :target: https://pypi.python.org/pypi/pytest-socket

.. image:: https://img.shields.io/pypi/pyversions/pytest-socket.svg :target: https://pypi.python.org/pypi/pytest-socket

.. image:: https://github.com/miketheman/pytest-socket/workflows/Python%20Tests/badge.svg :target: https://github.com/miketheman/pytest-socket/actions?query=workflow%3A%22Python+Tests%22 :alt: Python Tests

.. image:: https://api.codeclimate.com/v1/badges/1608a75b1c3a20211992/maintainability :target: https://codeclimate.com/github/miketheman/pytest-socket/maintainability :alt: Maintainability

.. image:: https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiketheman%2Fpytest-socket.svg?type=shield :target: https://app.fossa.io/projects/git%2Bgithub.com%2Fmiketheman%2Fpytest-socket?ref=badge_shield :alt: FOSSA Status

A plugin to use with Pytest to disable or restrict 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 through Python's socket interface.

Requirements

  • Pytest_ 3.6.3 or greater

Installation

You can install "pytest-socket" via pip_ from PyPI_::

$ pip install pytest-socket

Usage

  • Run pytest --disable-socket, tests should fail on any access to socket or libraries using socket with a SocketBlockedError.

    To add this flag as the default behavior, add this section to your pytest.ini or setup.cfg:

    .. code:: ini

    [pytest] addopts = --disable-socket

    or update your conftest.py to include:

    .. code:: python

    from pytest_socket import disable_socket

    def pytest_runtest_setup(): disable_socket()

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

    .. code:: python

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

    @pytest.mark.enable_socket def test_explicitly_enable_socket_with_mark(): assert socket.socket(socket.AF_INET, socket.SOCK_STREAM)

  • To allow only specific hosts per-test:

    .. code:: python

    @pytest.mark.allow_hosts(['127.0.0.1']) def test_explicitly_enable_socket_with_mark(): assert socket.socket.connect(('127.0.0.1', 80))

or for whole test run

.. code:: ini

[pytest]
addopts = --allow-hosts=127.0.0.1,127.0.1.1

Contributing

Contributions are very welcome. Tests can be run with pytest_, 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

.. image:: https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiketheman%2Fpytest-socket.svg?type=large :target: https://app.fossa.io/projects/git%2Bgithub.com%2Fmiketheman%2Fpytest-socket?ref=badge_large :alt: FOSSA Status

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.

.. _Cookiecutter: https://github.com/audreyr/cookiecutter .. _@hackebrot: https://github.com/hackebrot .. _MIT: http://opensource.org/licenses/MIT .. _cookiecutter-pytest-plugin: https://github.com/pytest-dev/cookiecutter-pytest-plugin .. _file an issue: https://github.com/miketheman/pytest-socket/issues .. _pytest: https://github.com/pytest-dev/pytest .. _tox: https://tox.readthedocs.io/en/latest/ .. _pip: https://pypi.python.org/pypi/pip/ .. _PyPI: https://pypi.python.org/pypi .. _@hangtwenty: https://github.com/hangtwenty .. _StackOverflow question: https://stackoverflow.com/a/30064664 .. _@miketheman: https://github.com/miketheman

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].