Code Monkey home page Code Monkey logo

pytest-asyncio-cooperative's Introduction

image

Use asyncio (cooperative multitasking) to run your I/O bound test suite efficiently and quickly.

Quickstart

Compatibility

pytest-asyncio is NOT compatible with this plugin. Please uninstall pytest-asyncio or pass this flag to pytest -p no:asyncio

Fixtures

It's recommended that async tests use async fixtures.

Goals

  • Reduce the total run time of I/O bound test suites via cooperative multitasking
  • Reduce system resource usage via cooperative multitasking

Pros

  • An I/O bound test suite will run faster (ie. individual tests will take just as long. The total runtime of the entire test suite will be faster)
  • An I/O bound test suite will use less system resources (ie. only a single thread is used)

Cons

  • Order of tests is not guaranteed (ie. some blocking operations might taken longer and affect the order of test results)
  • Tests MUST be isolated from each other (ie. NO shared resources, NO mock.patch). However, note that locks can be used to ensure isolation.
  • There is NO parallelism, CPU bound tests will NOT get a performance benefit

Mocks & Shared Resources

When using mocks and shared resources cooperative multitasking means tests could have race conditions.

In this case you can use locks:

In the above example it's important to put the lock fixture on the far left-hand side to ensure mutual exclusivity.

Timeouts

Tests are automatically cancelled after a timeout of 600s. You can change this with the --asyncio-task-timeout option or by adding an asyncio_task_timeout entry to your pytest.ini file.

Maximum Asynchronous Tasks

Sometimes you want to limit the number of tasks running concurrently. You can set a maximum with the --max-asyncio-tasks option by adding a max_asyncio_tasks entry to your pytest.ini file.

pytest-asyncio-cooperative's People

Contributors

willemt avatar gerlero avatar functionpointer avatar dkropachev avatar wandel avatar ipburbank avatar kpetremann avatar clouder0 avatar rehan-mateusz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.