项目作者: SalmonMode

项目描述 :
A functional testing tool for Python
高级语言: Python
项目地址: git://github.com/SalmonMode/contextional.git
创建时间: 2017-02-17T16:13:00Z
项目社区:https://github.com/SalmonMode/contextional

开源协议:MIT License

下载


Build status
PyPI version
Docs

Contextional

A context-based functional testing tool for Python

Installation

To install it, just run:

  1. pip install contextional

“contex-tional?”

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).

What does it do?

Contextional does 3 things:

  1. It gives you more organized test output by breaking tests into a hierarchical structure based on how the tests were defined, letting you provide descriptive names for each layer of the hierarchy as well as the tests themselves.
  2. It lets you predefine a hierarchy of tests that can be easily reused in as many places as you’d like.
  3. It allows you to control the exact order in which your tests and fixtures occur, which can be extremely useful for writing comprehensive, functional test suites where you need to test as you go.

What does it look like?

code:

  1. from contextional import GCM
  2. with GCM("Predefined Group") as PG:
  3. @GCM.add_test("value is still 2")
  4. def test(case):
  5. case.assertEqual(
  6. GCM.value,
  7. 2,
  8. )
  9. with GCM("Main Group") as MG:
  10. @GCM.add_setup
  11. def setUp():
  12. GCM.value = 0
  13. @GCM.add_test_setup
  14. def testSetUp():
  15. GCM.value += 1
  16. @GCM.add_test("value is 1")
  17. def test(case):
  18. case.assertEqual(
  19. GCM.value,
  20. 1,
  21. )
  22. @GCM.add_test("value is 2")
  23. def test():
  24. assert GCM.value == 2
  25. with GCM.add_group("Child Group"):
  26. @GCM.add_setup
  27. def setUp():
  28. GCM.value += 1
  29. @GCM.add_test("value is now 3")
  30. def test():
  31. assert GCM.value == 3
  32. @GCM.add_teardown
  33. def tearDown():
  34. GCM.value -= 1
  35. GCM.includes(PG)
  36. MG.create_tests()

output

  1. Main Group
  2. value is 1 ... ok
  3. value is 2 ... ok
  4. Child Group
  5. value is now 3 ... ok
  6. Predefined Group
  7. value is still 2 ... ok
  8. ----------------------------------------------------------------------
  9. Ran 4 tests in 0.008s
  10. OK