Skip to content

Commit 61b996e

Browse files
style: pre-commit fixes
1 parent 372ccef commit 61b996e

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

docs/pages/principles/testing.md

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -486,61 +486,67 @@ def test_pytest(mocker):
486486

487487
The range of inputs that test cases validate is an important decision.
488488

489-
When the need for extensive testing starts to conflict with the readability of test cases
490-
and their usefulness as documentation for users and other developers, the tests should
491-
be re-organized into public-facing (concise, expressive, easily readable),
492-
and technical (complex, extensive) test files.
489+
When the need for extensive testing starts to conflict with the readability of
490+
test cases and their usefulness as documentation for users and other developers,
491+
the tests should be re-organized into public-facing (concise, expressive, easily
492+
readable), and technical (complex, extensive) test files.
493493

494494
- To maintain readability:
495-
- tests may need to include fewer inputs
495+
- tests may need to include fewer inputs
496496
- extensive edgecase testing may be moved into different sections or files
497497
- the code itself may need to be refactored
498-
- Avoid testing invalid input; the range of invalid input is infinite, and
499-
is the programming equivalent of trying to prove a negative.
500-
- Focus on inputs relevant to the code under test, and avoid testing the code in dependencies.
501-
Some integration testing of specific behaviors your code relies on is justifiable.
502-
- [Fuzz Tests](#fuzz-tests) are the best place to handle extensive and exhaustive input testing.
503-
498+
- Avoid testing invalid input; the range of invalid input is infinite, and is
499+
the programming equivalent of trying to prove a negative.
500+
- Focus on inputs relevant to the code under test, and avoid testing the code in
501+
dependencies. Some integration testing of specific behaviors your code relies
502+
on is justifiable.
503+
- [Fuzz Tests](#fuzz-tests) are the best place to handle extensive and
504+
exhaustive input testing.
504505

505506
### In Public Interface Tests
506507

507-
These are the most appropriate place to test certain invalid inputs and dependencies.
508-
Public Interface tests act like a contract with users; each behavior that is tested is like a promise that
509-
users can rely on, and expect that it will not change without warning (and probably a major version bump).
510-
So any input/output and side-effects included in these tests should be considered *officially supported behavior*
511-
and given careful consideration.
508+
These are the most appropriate place to test certain invalid inputs and
509+
dependencies. Public Interface tests act like a contract with users; each
510+
behavior that is tested is like a promise that users can rely on, and expect
511+
that it will not change without warning (and probably a major version bump). So
512+
any input/output and side-effects included in these tests should be considered
513+
_officially supported behavior_ and given careful consideration.
512514

513515
### In project level integration tests
514516

515-
These are a good place to handle more extensive input testing. Integration tests already tend to be more verbose,
516-
with a lot of setup and teardown, and much more behavior to cover than other kinds of tests.
517-
These are the kinds of tests that should focus on edgecases.
518-
517+
These are a good place to handle more extensive input testing. Integration tests
518+
already tend to be more verbose, with a lot of setup and teardown, and much more
519+
behavior to cover than other kinds of tests. These are the kinds of tests that
520+
should focus on edgecases.
519521

520522
### In Unit Tests
521523

522-
Unit Tests should focus on the "happy-path" of execution. In most cases one representative
523-
example of the *expected* input is sufficient. The test case should illustrate how the unit
524-
is expected to be used.
524+
Unit Tests should focus on the "happy-path" of execution. In most cases one
525+
representative example of the _expected_ input is sufficient. The test case
526+
should illustrate how the unit is expected to be used.
525527

526-
Invalid input should only be tested when the unit itself includes logic to handle that invalid input.
528+
Invalid input should only be tested when the unit itself includes logic to
529+
handle that invalid input.
527530

528531
for example, this code:
532+
529533
```python
530534
def foo(x: int):
531535
return x + 1
532536
```
533-
should not test its behavior when passed a string (the type annotation already covers that).
537+
538+
should not test its behavior when passed a string (the type annotation already
539+
covers that).
534540

535541
This code should be tested with a string, to cover the exception path.
542+
536543
```python
537544
def bar(x):
538545
if type(x) is str:
539-
raise RuntimeError('invalid input')
546+
raise RuntimeError("invalid input")
540547
return x + 1
541548
```
542549

543-
544550
## Additional Types of Test Suites
545551

546552
A non-exhaustive discussion of some common types of tests.

0 commit comments

Comments
 (0)