Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

AssertionError being raised instead of showing "Difference (LHS vs RHS)" #367

Open
nonamethanks opened this issue Feb 22, 2023 · 2 comments

Comments

@nonamethanks
Copy link

nonamethanks commented Feb 22, 2023

from ward import test

def assert_something(l, v):
    assert l == v

@test("test", tags=["test"])
def _() -> None:
    assert_something(1, 2)

Compare the result of this:
image
with what happens if the assert is in the main body:
image

How do I make it print the proper output normally? For large tests it becomes a mess to figure out what's wrong unless I assign a million variables in each function in order to inspect the locals. I checked the documentation and found no mention of reusing assertions like this.

@StefanBRas
Copy link

From a quick view it looks like ward will modify assert statements into its own assert functions from ward.expect. However this probably only happens inside functions decorated with @test.

You can use these assertion functions directly. Your example would then become

from ward import test
from ward.expect import assert_equal

def assert_something(l, v):
    assert_equal(l,v, "") # must have a msg

@test("test", tags=["test"])
def _() -> None:
    assert_something(1, 2)

@nonamethanks
Copy link
Author

Unfortunately these assert_ functions are not good enough. For one, they don't show the full traceback. Try putting the function assert_something in another file and importing it, and you'll see that the test will then only print the code for the current file on failures (the _() function, not any individual assert failing inside assert_something), which is pretty much useless if you're doing any serious testing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants