Python Unittest

Writing test cases, assertions, mocking API calls, and running test runner pipelines using unittest.

Lord1Egypt Updated 2 repo stars

File contents

Python Unittest

Overview

unittest is the built-in testing framework in Python, offering clean class-based test configurations.

When to Use This Skill

Use to create unit tests and verify the logic correctness of your code modules.

Quick Start (with runnable code examples)

import unittest

def add_values(x, y):
    return x + y

class TestMathOperations(unittest.TestCase):
    def test_addition(self):
        self.assertEqual(add_values(2, 3), 5)

if __name__ == '__main__':
    unittest.main()

Advanced Usage

Configure test fixtures (setUp/tearDown), mock external requests using unittest.mock.patch, and assert custom errors.

Key References

Dependencies

  • Python Standard Library

Lord1Egypt/ai-skillforge/tree/main/skills/gemini/python-unittest commit 6bb4f4f8d2

Frequently asked questions

npx skillmds@latest add lord1egypt/python-unittest