torment.contexts
— Testing Contexts¶
-
class
torment.contexts.
MetaContext
(name, bases, dct) → None[source]¶ torment.TestContext
class creator.Generates all testing methods that correspond with the fixtures associated with a
torment.TestContext
. Also updates the definitions ofmocks_mask
andmocks
to include the union of all involved classes in the creation process (all parent classes and the class being created).When creating a
torment.TestContext
subclass, ensure you specify this class as its metaclass to automatically generate test cases based on itsfixture_classes
property.-
module
¶ Actual module name corresponding to this context’s testing module.
-
-
class
torment.contexts.
TestContext
(methodName='runTest')[source]¶ Environment for Fixture execution.
Provides convenience methods indicating the environment a Fixture is executing in. This includes a references to the real module corresponding to the context’s testing module as well as a housing for the assertion methods.
Inherits most of its functionality from
unittest.TestCase
with a couple of additions. TestContext does extend setUp.When used in conjunction with
torment.MetaContext
, thefixture_classes
property must be an iterable of subclasses oftorment.fixtures.Fixture
.Properties
module
Public Methods
patch
Class Variables
Mocks_mask: set of mocks to mask from being mocked Mocks: set of mocks this TestContext provides -
module
¶ Actual module name corresponding to this context’s testing module.
-
patch
(name: str, relative: bool=True) → None[source]¶ Patch name with mock in actual module.
Sets up mock objects for the given symbol in the actual module corresponding to this context’s testing module.
Parameters
Name: the symbol to mock—must exist in the actual module under test Relative: prefix actual module corresponding to this context’s testing module to the given symbol to patch