NicolasLacroix / PyUnitPerf

A simple API for unit testing a Python project's performances and memory leaks :zap::wheelchair:.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

A simple API for unit testing a Python project's performances and memory leaks :zap::wheelchair:.

License:Apache License 2.0


Languages

Language:Python 100.0%