Giter VIP home page Giter VIP logo

pyunitperf's Introduction

PyUnitPerf

Python package Python versions License

A simple and lightweight API for unit testing a Python ๐Ÿ project's performances โšกโ™ฟ.

From Python 3.5 to 3.8, easily improve your project's performances tests through the use of dedicated decorators.

Table of contents

Memory testing

Memory overload assertions

The memory overload assertions are possible thanks to the @memory_not_exceed decorator.

A simple TestCase associated to this decorator does the job :

class TestLimitMemoryUsage(unittest.TestCase):
    """
    This class illustrates the use of the memory_not_exceed decorator.
    """
    @memory_not_exceed(threshold=0)
    def test_memory_usage_exceed(self):
        """
        This test won't pass due to a very low threshold.
        """
        return list(range(1000)) * 1

    @memory_not_exceed(threshold=1000)
    def test_memory_usage_not_exceed(self):
        """
        This test passes due to a very high threshold.
        """
        return list(range(1000)) * 1

Memory leaks assertions

The memory leaks assertions are possible thanks to the @memory_not_leak decorator.

Once again, a simple TestCase associated to this decorator does the job :

class TetsMemoryLeaksDetection(unittest.TestCase):
    """
    This class illustrates the use of the memory_not_leak decorator.
    """
    leaking_list = []

    def leak(self):
        """
        Generates a memory leak involving the leaking_list.
        """
        self.leaking_list.append("will leak")

    @memory_not_leak()
    def test_memory_leaks(self):
        """
        This test won't pass due to a memory leak.
        """
        self.leak()

    @memory_not_leak()
    def test_memory_not_leak(self):
        """
        This test passes due to the absence of memory leak.
        """
        valid_list = []
        valid_list.append("won't leak")

pyunitperf's People

Contributors

nicolaslacroix avatar

Watchers

 avatar

pyunitperf's Issues

[Memory] Add exclude parameter

Add exclude parameter for memory decorators to ignore specific statement/module.

Consider setting a global config to avoid specifying this exclude parameter for each tested function.

Add memory limit Test

Add a decorator to test that a given function or class does not exceed a given threshold.

[Memory] Improve failure explanation

Create a dedicated function for the failure explanation.

Specify the total memory usage, the snippet causing the failure and other stats for each snippets.

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.