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
Addition of "hypothesis usage" in test cases of tests/reshape/test_util.py as kind of POC.
Incorporate review comments.
Resolve flake8 warning.
Add section for hypothesis in contributing.rst
Copy file name to clipboardExpand all lines: doc/source/contributing.rst
+13-1
Original file line number
Diff line number
Diff line change
@@ -776,14 +776,18 @@ Tests that we have ``parametrized`` are now accessible via the test name, for ex
776
776
test_cool_feature.py::test_series[int8] PASSED
777
777
778
778
Transitioning to ``hypothesis``
779
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
779
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
780
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.
781
+
781
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
+
782
784
Imagine if some framework could generate random input examples based on the property/specification of the function being tested. That is exactly what hypothesis does by generating the input data based on some set of specifications provided by the user.
783
785
e.g suppose we have to test python's sum function for a list of int.
784
786
785
787
Here is a sample test case using pytest:
788
+
786
789
.. code-block:: python
790
+
787
791
import pytest
788
792
789
793
@pytest.mark.parametrize('seq', [
@@ -799,7 +803,9 @@ Here is a sample test case using pytest:
Compare it with below example for the same test case using hypothesis.
819
+
813
820
.. code-block:: python
821
+
814
822
from hypothesis import strategies as st
815
823
from hypothesis import given
816
824
@@ -822,15 +830,19 @@ Compare it with below example for the same test case using hypothesis.
822
830
total += item
823
831
assert sum(seq) == total
824
832
833
+
825
834
output of test cases:
835
+
826
836
.. code-block:: shell
837
+
827
838
collecting ... collected 1 item
828
839
hypothesis_example.py::test_sum PASSED [100%]
829
840
830
841
========================== 1 passed in 0.33 seconds ===========================
831
842
832
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.
833
844
For more information about hypothesis or in general about property based testing, check below links:
0 commit comments