Improved TestCase class
Project description
Improved TestCase Class
dectest.TestCase is a drop-in replacement for unittest.TestCase with
a few added features.
Tests, Setup, and Teardown with Decorators
Tests can optionally be marked using the @test decorator, instead of
prefixing the method name with test. The following test case class
contains two tests:
from dectest import TestCase, test
class MyTest(TestCase):
def test_foo(self):
pass
@test
def bar(self):
pass
Setup and teardown methods can be marked using the @before and @after
decorators, respectively. A class can have multiple setup and teardown
methods:
from dectest import TestCase, before, after
class MyTest(TestCase):
@before
def setup_stuff(self):
pass
@before
def setup_more_stuff(self):
pass
@after
def teardown_all_stuff(self):
pass
While the order of execution inside a class is undefined and should not be relied upon, it is guaranteed that setup methods in super-classes are executed before methods in sub-classes, and teardown methods in sub-classes are executed before teardown method in super-classes:
from dectest import TestCase, before, after
class MySuperTest(TestCase):
@before
def super_setup(self):
print("setup first")
@after
def super_teardown(self):
print("teardown second")
class MySubTest(MySuperTest):
@before
def sub_setup(self):
print("setup second")
@after
def sub_teardown(self):
print("teardown first")
Patch Support
dectest.TestCase has a patch() method to install a mock using
unittest.mock.patch(). This patch is removed during test
teardown:
from dectest import TestCase, test
class MyPatchTest(TestCase):
@test
def foo(self):
exit = self.patch("sys.exit") # will be stopped during teardown
# call implementation
exit.assert_called_with(1)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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 dectest-1.1.1-py3-none-any.whl.
File metadata
- Download URL: dectest-1.1.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
699e3ade7853448306e1471ed2e4b9e2c229e381a17c05fb3c8f2363ec8f71d5
|
|
| MD5 |
dce70ac84178c5f61c581b6ea860b54d
|
|
| BLAKE2b-256 |
ff999605a8b6db98c44f338c7b4429cb87c8826d47c85ee2b42e96793fd224ef
|