Skip to main content

Hacks to assist with testing.

Project description

Hacks to assist with testing.

Latest release 20240623: New assertSingleThread() function to check that there are no left over Threads.

Function assertSingleThread(include_daemon=False)

Test that the is only one Thread still running.

Function product_test(*da, **dkw)

Decorator for test methods which should run subTests against the Cartesian products from params.

A specific TestCase would define its own decorator and apply it throughout the suite. Here is an example from cs.vt.datadir_tests:

def multitest(test_method): return product_test( test_method, datadirclass=[DataDir, RawDataDir], indexclass=[ indexclass_by_name(indexname) for indexname in sorted(indexclass_names()) ], hashclass=[ HASHCLASS_BY_NAME[hashname] for hashname in sorted(HASHCLASS_BY_NAME.keys()) ], )

whose test suite then just decorates each method with @multitest:

@multitest
def test000IndexEntry(self):
    ....

Note that because there must be setup and teardown for each product, the TestCase class may well have empty setUp and tearDown methods and instead is expected to provide:

  • product_setup(self,**params): a setup method taking keyword arguments for each product
  • product_teardown(self): the corresponding testdown method There are called around each subTest.

Class SetupTeardownMixin

A mixin to support a single setupTeardown() context manager method.

Method SetupTeardownMixin.setUp(self): Run super().setUp() then the set up step of self.setupTeardown().

Method SetupTeardownMixin.tearDown(self): Run the tear down step of self.setupTeardown(), then super().tearDown().

Release Log

Release 20240623: New assertSingleThread() function to check that there are no left over Threads.

Release 20230109:

  • @product_test decorator for running test matrices.
  • SetupTeardownMixin providing unittest setUp/tearDown from setupTeardown context manager method.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cs.testutils-20240623.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

cs.testutils-20240623-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file cs.testutils-20240623.tar.gz.

File metadata

  • Download URL: cs.testutils-20240623.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.6

File hashes

Hashes for cs.testutils-20240623.tar.gz
Algorithm Hash digest
SHA256 39518669cfc74f612ba7edafb8a867d95c545b12839630733648fd1809fdca5f
MD5 460f7b4b69fe6922c9f8a29e43c39f4c
BLAKE2b-256 7fa581014b4ee062a5df1d6ec9cc27abf8d47f9e64ea8f78c8be44290f4c98a9

See more details on using hashes here.

File details

Details for the file cs.testutils-20240623-py3-none-any.whl.

File metadata

File hashes

Hashes for cs.testutils-20240623-py3-none-any.whl
Algorithm Hash digest
SHA256 858e73f18c12e0301ac87014c29c39f4dfe7c5d7320e23df175f9f7ba4b446af
MD5 0da2bc4e7cbbc0685ed0e7728b995cc8
BLAKE2b-256 5eb71805442143484300836e28f431645c5b68d4e8b227c56488d952357e0f7d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page