On 25/10/2023 05.45, o1bigtenor wrote:
On Tue, Oct 24, 2023 at 8:35 PM Chris Angelico via Python-list
<python-list@python.org> wrote:

3. Catch the failure before you commit and push. Unit tests are great for this.

Where might I find such please.

You don't "find" unit tests; you write them. A unit test tests
a specific function or program.

Ideally, you write each unit test *before* you write the function
that it tests.

For instance, suppose that you were writing a function to calculate
the distance between two points. We know the following things about
distance:
1. The distance from a point to itself is zero.
2. The distance between two distinct points is positive.
3. The distance from A to B is equal to the distance from B to A.
4. The distance from A to B plus the distance from B to C is at
   least as large as the distance from A to C.

You would write unit tests that generate random points and apply
your distance function to them, checking that each of these
conditions is satisfied. You'd also write a few tests of hard-coded
points,such as:
- Distance from (0,0) to (0,y) is y
- Distance from (0,0) to (x,0) is x
- Distance from (0,0) to (3,4) is 5
- Distance from (0,0) to (12,5) is 13

The python ecosystem provides many tools to simplify writing and
running unit tests. Somebody has already mentioned "unittest". I
use this one all of the time. There are also "doctest", "nose",
"tox", and "py.test" (none of which I've used).

--
Michael F. Stemper
Life's too important to take seriously.

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to