A functional testing tool for Python
A context-based functional testing tool for Python
To install it, just run:
pip install contextional
It’s a portmanteau of the words “context” and “functional”. These words were chosen because the tool works by using context managers (with
statements), and allows you to write functional tests (testing as you go).
Contextional does 3 things:
from contextional import GCM
with GCM("Predefined Group") as PG:
@GCM.add_test("value is still 2")
def test(case):
case.assertEqual(
GCM.value,
2,
)
with GCM("Main Group") as MG:
@GCM.add_setup
def setUp():
GCM.value = 0
@GCM.add_test_setup
def testSetUp():
GCM.value += 1
@GCM.add_test("value is 1")
def test(case):
case.assertEqual(
GCM.value,
1,
)
@GCM.add_test("value is 2")
def test():
assert GCM.value == 2
with GCM.add_group("Child Group"):
@GCM.add_setup
def setUp():
GCM.value += 1
@GCM.add_test("value is now 3")
def test():
assert GCM.value == 3
@GCM.add_teardown
def tearDown():
GCM.value -= 1
GCM.includes(PG)
MG.create_tests()
Main Group
value is 1 ... ok
value is 2 ... ok
Child Group
value is now 3 ... ok
Predefined Group
value is still 2 ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.008s
OK