On 07/09/2020 17:13, tobia...@gmx.de wrote:
I wasn't aware of the fact that many contributors to sage are users in
the first place, and contributors second. So they are probably more
familiar with sage's doctests than with unittests. That's good input,
thanks!
For me, it's actually the converse: I didn't know what doctests are, but
was familiar with the concept of unit tests. What do you think about
recommending both ways to write unit tests (as doctest-like TESTS, and
unittest python files in src/sage/tests) in the developer documentation,
to help onboarding of developers from the broader python community?
(Keeping the requirement that methods need to have doctests using the
EXAMPLES tag.)
As for the advantages of unittests over doctests (given my limited
experience with the latter):
- Can easily run and debug single tests
- Get full intellisense and linting support for writing tests
- Easily share common initialization / teardown code between tests
- Stronger assertions not only relying on string-comparisons
- Supports generation of tests based on (external) data, e.g. if you
want to test a method against a range of input -> output pairs
- Ability to mock external objects and services (web resources,
libraries etc) and use dependency injection
- Test code can rely on additional libraries and other code, that
doesn't need to be shipped
For the first point you mention, please see the thread "doctest a single
function or class" at
https://groups.google.com/forum/#!msg/sage-devel/mlcfDY-Hur0/Ws8sIP3SAwAJ
that ended with an astute observation by embray...
I would find it useful. Better yet, is having an editor keybinding to
run the doctest of the current method or block (by cursor position).
Assertions in a doctest can be essentially arbitrary, like foo(x,y) ==
bar(y,x) with the output True or False.
Regards,
TB
--
You received this message because you are subscribed to the Google Groups
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sage-devel/db103acc-c763-34a5-0fa0-4275566579d1%40gmail.com.