Two days ago I've added to Leo a new command 'execute-pytest' which runs
like `run-selected-unit-tests-locally`, but executes test functions in
@test nodes as if they were in a file processed by pytest.
To use this command one must have pytest installed. Command will look in
the subtree of the selected node for all nodes whose headlines starts with
'@test'. If no such node has been found, command will look into the parents
of selected node for `@test` headlines. Every found node will be searched
for functions whose name starts with 'test_' and each test function will be
executed using assert rewriting as pytest does.
Here is an example:
def add_2(x):
return x + 2
def times_3(x):
return x * 3
def inc(x):
return x + 1
def test_a():
assert inc(3) == 4.1
def test_b():
assert times_3(add_2(inc(3.1))) == times_3(inc(5))
and here is the output in the Log pane:
----------Failure-------------
assert 4 == 4.1
+ where 4 = inc(3)
----------Failure-------------
assert 18.299999999999997 == 18
+ where 18.299999999999997 = times_3(6.1)
+ where 6.1 = add_2(4.1)
+ where 4.1 = inc(3.1)
+ and 18 = times_3(6)
+ where 6 = inc(5)
failed:2 tests
changing the constants 3.1 to 3 and 4.1 to 4, all tests pass.
Pytest machinery rewrites each assert statement to show not only the final
two values that are compared, but all intermediate results in calcualting
both sides of the expression. This greatly reduces the amount of work on
formatting assertion messages. Quite often pytest generated messages are
sufficient.
Of course, test scripts have access to g, c and p as usual.
Vitalije
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/leo-editor/1a6a64ef-1d2c-4d5e-8d83-4125be5f6612%40googlegroups.com.