Quick.py is a property-based testing library for Python inspired by the Haskell library QuickCheck. The core idea of QuickCheck is that instead of enumerating expected input and output for unit tests, you write properties about your function that should hold true for all inputs. This lets you write concise, powerful tests.
pip install quick.py Basic example:
# example.pyfromquick.featuresimportQuickCheckqc=QuickCheck(max_count=100) @qc.forall('Associative property of addition for integers')defprop(x: int, y: int): return (x+y) == (y+x) TestAddtion=qc.as_testcase()>>> nosetests example.py .................................................................................................... ---------------------------------------------------------------------- Ran 100 tests in 0.061s OK Custom generators:
# example.pyfromquick.featuresimportQuickCheckfromquick.generatorsimportnumberfromquick.arbitraryimportAqc=QuickCheck(max_count=100) defnon_empty_list(el: number, ls: [number]): """ Generator which always returns non empty list """ls.append(el) returnls@qc.forall('The first element of a sorted list should be always lesser or eq than the last')defprop(x: non_empty_list): sorted_x=sorted(x) first=sorted_x[0] last=sorted_x[-1] returnfirst<=lastTestSort=qc.as_testcase()>>> nosetests example.py .................................................................................................... ---------------------------------------------------------------------- Ran 100 tests in 0.070s OK - Integration with unittests library
- Custom generators
- Simplification/Shrinking of failure input (in progress)
defworking_time(a: A): day=a.choose_one('Monday', 'Tuesday', 'Wednesday', 'Thursday') hour=a.choose(8, 17) return{'day': day, 'hour': hour}classUser(object): def__init__(self, name, age): self.name=nameself.age=agedefuser_gen(name: str, a: A): age=a.choose(18, 100) returnUser(name, age) @forall('Valid users')defprop(user: user_gen): return ...TBD, It's a trial implementation, and has limited functionalities yet.
Oups, sorry
For feature requests and bug reportssubmit an issue to the GitHub issue tracker for quick.py.