You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/source/contributing.rst
+3-37
Original file line number
Diff line number
Diff line change
@@ -777,45 +777,12 @@ Tests that we have ``parametrized`` are now accessible via the test name, for ex
777
777
778
778
Using ``hypothesis``
779
779
~~~~~~~~~~~~~~~~~~~~
780
-
With the transition to pytest, things have become easier for testing by having reduced boilerplate for test cases and also by utilizing pytest's features like parametizing, skipping and marking test cases.
780
+
With the usage of pytest, things have become easier for testing by having reduced boilerplate for test cases and also by utilizing pytest's features like parametizing, skipping and marking test cases.
781
781
782
782
However, one has to still come up with input data examples which can be tested against the functionality. There is always a possibility to skip testing an example which could have failed the test case.
783
783
784
784
Hypothesis is a python package which helps in overcoming this issue by generating the input data based on some set of specifications provided by the user.
785
-
e.g suppose we have to test python's sum function for a list of int.
========================== 4 passed in 0.06 seconds ===========================
816
-
817
-
818
-
Compare it with below example for the same test case using hypothesis.
785
+
e.g consider the test case for testing python's sum function for a list of int using hypothesis.
819
786
820
787
.. code-block:: python
821
788
@@ -840,8 +807,7 @@ output of test cases:
840
807
841
808
========================== 1 passed in 0.33 seconds ===========================
842
809
843
-
The main difference in above example is use of a decorator "@given(st.lists(st.integers()))" which if applied to testcase function, generates some random list of int, which is then assigned to parameter of test case.
844
-
Above example clearly helps in adding more coverage for our test functions.
810
+
In above example by applying a decorator "@given(st.lists(st.integers()))" to the unit test function, we have directed hypothesis to generate some random list of int as input forthe test function, which eventually helpsin adding more coverage for our test functions by generating random input data.
845
811
846
812
For more information about hypothesis or in general about property based testing, check below links:
0 commit comments