Logging Test Case With Helper Methods
Project description
kissut - Python Unittesting Utilities
Provides a simple automatic test case that sets up a new log each time tests are run. Also provides some basic methods to assist with configuration and file management when running tests
Usage
Installation:
pip install kissut
LoggingTestCase subclasses unittest.TestCase, so when creating your tests, simply subclass LoggingTestCase instead of TestCase. LoggingTestCase sets up a unittest directory wkdir/unittest/ and saves log directories there:
from kissut import LoggingTestCase
import os
# all test classes must derive from unittest.TestCase, which LoggingTestCase does...
class TestExample(LoggingTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# this loads the test configuration file
cls.cfg = cls.getConfig()
def test_a_isTrue(self):
s = self.randString()
self.logger.debug("s: {}".format(s))
self.assertTrue(s)
def test_b_saveWorkData(self):
self.cfg["data"] = "testData.json"
fqfn = self.dumpWkDirData(data={"a": "b"}, filename=self.cfg["data"])
self.logger.debug("file name: {}".format(self.cfg["data"]))
self.assertTrue(os.path.exists(fqfn))
def test_c_isPresent(self):
self.logger.debug("cfg: {}".format(self.cfg))
d = self.loadWkDirData(self.cfg["data"])
self.logger.debug("data: {}".format(d))
self.assertIsNotNone(d)
This produces the following directory structure after running it twice (the first time will abort as it creates the config file):
<project folder>
└── wkdir
└── unittest
├── 20260306T155251
│ └── log.txt
├── 20260306T160132
│ ├── log.txt
│ └── testData.json
└── testConfig.json
Obviously loading a config file in the setUpClass method is not required, it is just something I find useful, especially when a connection string or url is required for testing.
Some additional things to note, a simple random string method is included, as are dump and save methods for data to the working directory, and an initialized logger on the test case object.
If you prefer to save the logs or test config in another location, create a session-specific or user environment variable that defines path to the alternative configuration file. The contents of the alternative configuration file should be formatted like the following, obviously replacing the values as appropriate:
{
"logCfgFile": "wkdir/alt_unittest/logConfig.json",
"testCfgFile": "wkdir/alt_unittest/testConfig.json"
}
Cloning For Development
Set up a virtual environment. Once an environment is set up, activate it and add dependencies with the following:
pip install -r requirements/dev.txt
The dev.txt file includes:
- BLACK, a code formatter, see notes at the bottom of this file for details
- build, which provides the support for the building of the package
To run tests:
python -m unittest discover -s tests/
The run the following to confirm the alternative configuration works, ensuring the unittest configuration and log directories get saved in the wkdir/alt_unittest directory:
source tests/runAltUnittest.sh
Does the same thing as
export KISSUT_CFG_FILE="tests/altConfig.json"
python -m unittest discover -s tests/
Code Formatting
Code formatting is done using BLACK. BLACK allows almost no customization to how code is formatted with the exception of line length, which has been set to 119 characters.
Use the following to bulk format files:
black . -l 144
Creating A New Release
Please do the following when making a new release, most are documented above:
- Run tests
- Code format
- Be sure to update the change log and _metadata.json with version and notes
- git add, commit, and push changes
- run the following code to generate a wheel:
python -m build
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kissut-1.1.0.tar.gz.
File metadata
- Download URL: kissut-1.1.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed5c7dd046875065d3a895a104573d8ace81c220d2f4291de781ff2a39605add
|
|
| MD5 |
44b1c17c548b6318e2b728a6602dd994
|
|
| BLAKE2b-256 |
f3433b241bdc96c75d16ea713e6032a546337d640cf5f68a5978dce605ff83bd
|
Provenance
The following attestation bundles were made for kissut-1.1.0.tar.gz:
Publisher:
publish.yml on joemarchionna/kissut
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kissut-1.1.0.tar.gz -
Subject digest:
ed5c7dd046875065d3a895a104573d8ace81c220d2f4291de781ff2a39605add - Sigstore transparency entry: 1186463048
- Sigstore integration time:
-
Permalink:
joemarchionna/kissut@fa6af576e6ce752b1e5634c13642ef55ca6fe50f -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/joemarchionna
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fa6af576e6ce752b1e5634c13642ef55ca6fe50f -
Trigger Event:
release
-
Statement type:
File details
Details for the file kissut-1.1.0-py3-none-any.whl.
File metadata
- Download URL: kissut-1.1.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30938e6f13c6bd5946ae66546a84c53a3ededd1b5ace452370e06107276e5acf
|
|
| MD5 |
ce58d84b883ed5e5499175d2d05226ba
|
|
| BLAKE2b-256 |
8b90621e4d269adde5a45576e7e0a06498d58a69d679d0759454e72b7c5dc436
|
Provenance
The following attestation bundles were made for kissut-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on joemarchionna/kissut
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kissut-1.1.0-py3-none-any.whl -
Subject digest:
30938e6f13c6bd5946ae66546a84c53a3ededd1b5ace452370e06107276e5acf - Sigstore transparency entry: 1186463056
- Sigstore integration time:
-
Permalink:
joemarchionna/kissut@fa6af576e6ce752b1e5634c13642ef55ca6fe50f -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/joemarchionna
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fa6af576e6ce752b1e5634c13642ef55ca6fe50f -
Trigger Event:
release
-
Statement type: