utest icon indicating copy to clipboard operation
utest copied to clipboard

Output like pytest

Open robsonpeixoto opened this issue 4 years ago • 0 comments

Disclaimer: I'm a scala noob that is reading https://www.handsonscala.com/ and I have no ideia if is possible do what I suggesting.

Reading this book I always try to write the code before reading the explanation, and I'm using utest to write my tests.

But use the assert without defining the variable before is very annoying to figure out why the test has failed. For exemplo, a hard to read assert message:

X AlgorithmsTest.breadthFirstSearch.breadthFirstSearch cyclic 40ms 
  utest.AssertionError: assert(breadthFirstSearch("b", graph) == Set("b", "a", "c", "FAKE"))
  graph: scala.collection.immutable.Map[String,Seq[String]] = Map(a -> List(b, c), b -> List(a), c -> List(b))
    utest.asserts.Asserts$.assertImpl(Asserts.scala:30)
    AlgorithmsTest$.$anonfun$tests$3(AlgorithmsTest.scala:13)

Is impossible to know the breadthFirstSearch("b", graph) output.

Is I define variable before, is easyer do read:

X AlgorithmsTest.breadthFirstSearch.breadthFirstSearch cyclic 46ms 
  utest.AssertionError: assert(result == expected)
  result: Set[String] = Set(a, b, c)
  expected: scala.collection.immutable.Set[String] = Set(b, a, c, FAKE)
    utest.asserts.Asserts$.assertImpl(Asserts.scala:30)
    AlgorithmsTest$.$anonfun$tests$3(AlgorithmsTest.scala:16)

A sugestion is use a output like the pytest do:

# content of test_sample.py
def inc(x):
    return x + 1


def test_answer():
    assert inc(3) == 5

Output:

$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-6.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 1 item

test_sample.py F                                                     [100%]

================================= FAILURES =================================
_______________________________ test_answer ________________________________

    def test_answer():
>       assert inc(3) == 5
E       assert 4 == 5
E        +  where 4 = inc(3)

test_sample.py:6: AssertionError
========================= short test summary info ==========================
FAILED test_sample.py::test_answer - assert 4 == 5
============================ 1 failed in 0.12s =============================

I have no ideia how complex is it, but I love this output.

robsonpeixoto avatar Sep 14 '20 17:09 robsonpeixoto