Python Unit Test package
Reason this release was yanked:
Beta release, use 1.0.0
Project description
Unit test package for Python
Unit test package for adding unit tests to your project.
Roadmap:
- 202312/202401: Publish to PyPi
Installation
Install from the Python package index:
pip install lily_unit_test
Usage
Create a file: my_class.py
"""
This example shows how to run a simple unit test.
"""
import lily_unit_test
class MyClass(object):
"""
Your class that will do something amazing.
"""
@staticmethod
def add_one(x):
return x + 1
@staticmethod
def add_two(x):
return x + 2
class MyTestSuite(lily_unit_test.TestSuite):
"""
The test suite for testing MyClass.
"""
@staticmethod
def test_add_one():
assert MyClass.add_one(3) == 4, 'Wrong return value'
@staticmethod
def test_add_two():
assert MyClass.add_two(3) == 5, 'Wrong return value'
if __name__ == '__main__':
"""
Run the test code, when not imported.
"""
MyTestSuite().run()
Run the file: python -m my_class.py
The output should look like:
2023-12-20 09:28:46.105 | INFO | Run test suite: MyTestSuite
2023-12-20 09:28:46.105 | INFO | Run test case: MyTestSuite.test_add_one
2023-12-20 09:28:46.106 | INFO | Test case MyTestSuite.test_add_one: PASSED
2023-12-20 09:28:46.106 | INFO | Run test case: MyTestSuite.test_add_two
2023-12-20 09:28:46.106 | INFO | Test case MyTestSuite.test_add_two: PASSED
2023-12-20 09:28:46.106 | INFO | Test suite MyTestSuite: 2 of 2 test cases passed (100.0%)
2023-12-20 09:28:46.106 | INFO | Test suite MyTestSuite: PASSED
Test suite object
Using the test suite as an object:
# Test suite from previous example
ts = MyTestSuite()
# Run method returns True if passed else False
result = ts.run()
print('Test passed:', result)
# Write log messages to file:
with open('test_report.txt', 'w') as fp:
# Write every message on a new line, the Pythonic way:
fp.writelines(map(lambda x: '{}\n'.format(x), ts.log.get_log_messages()))
# You could also use a loop (less Pythonic):
# for message in ts.log.get_log_messages():
# fp.write('{}\n'.format(message))
See test_suite.md for more details
Test runner
A test runner is an object to run test suites from a specific folder recursive.
from lily_unit_test import TestRunner
TestRunner.run('path/to/test_suites')
See test_runner.md for more details
(c) 2023 - LilyTronics (https://lilytronics.nl)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lily_unit_test-0.9.1.tar.gz
(9.6 kB
view hashes)
Built Distribution
Close
Hashes for lily_unit_test-0.9.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f2bf6f281761bebb2573bfb629063e9f1fc947f40b2efee713337682d8c6112 |
|
MD5 | f5299a8496b1bd3693327cb737c3c7a1 |
|
BLAKE2b-256 | f321bc3f5bdf494835771843116eb3fac3aaeef06b0bbb04b5c4fa47db93cde0 |