question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add some basic assert methods ?

See original GitHub issue
assertEqual(a, b) 
assertNotEqual(a, b) 
assertTrue(x) 
assertFalse(x)

It would potentially make logging easier/better.

Based on https://docs.python.org/3/library/unittest.html#unittest.TestCase.debug

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
JennToocommented, Feb 25, 2020

I’ve had a lot of luck with PyHamcrest for adding richer asserts to Python packages (except when using pytest, which seems to use dark magic to get fancy looking asserts).

I will grant that it’s a little verbose and I could see how some people might not like that.

from hamcrest import *


@cocotb.test()
def the_test(dut):
    yield Timer(1)
    assert_that(2+2, equal_to(7))
Send raised exception:
Traceback (most recent call last):
  File "/nix/store/srfxgwcc5x53c08m3gfwxkxjmg9pwyz1-python3.7-cocotb-1.2.0/lib/python3.7/site-packages/cocotb/decorators.py", line 259, in _advance
    return outcome.send(self._coro)
  File "/nix/store/srfxgwcc5x53c08m3gfwxkxjmg9pwyz1-python3.7-cocotb-1.2.0/lib/python3.7/site-packages/cocotb/outcomes.py", line 37, in send
    return gen.send(self.value)
  File "/home/jwilcox/repo/sim/test.py", line 10, in the_test
    assert_that(2+2, equal_to(7))
  File "/nix/store/fplm7gph3m4ws74zvqby6gqbjl7czqy1-python3.7-PyHamcrest-1.9.0/lib/python3.7/site-packages/hamcrest/core/assert_that.py", line 43, in assert_that
    _assert_match(actual=arg1, matcher=arg2, reason=arg3)
  File "/nix/store/fplm7gph3m4ws74zvqby6gqbjl7czqy1-python3.7-PyHamcrest-1.9.0/lib/python3.7/site-packages/hamcrest/core/assert_that.py", line 57, in _assert_match
    raise AssertionError(description)
AssertionError:
Expected: <7>
     but: was <4>
0reactions
github-actions[bot]commented, Nov 17, 2020

Has your question been resolved? If so please close this issue. If it has not been resolved, you may need to provide more information. If no more activity on this issue occurs in 7 days, it will be closed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assert Methods - Jenkov.com
This tutorial explains JUnits Assert class which contains a lot of methods for testing values against each other.
Read more >
Junit Assert & AssertEquals with Example - Guru99
In this tutorial, you will learn, JUnit Assert methods like Boolean, Null object, Identical, Assert Equals, Assert Array Equals, ...
Read more >
JUnit - Using Assertion - Tutorialspoint
All the assertions are in the Assert class. ... Let's use some of the above-mentioned methods in an example. Create a java class...
Read more >
JUnit 5 Basics 11 - Assert methods - YouTube
Note: This course is still in progress. Please subscribe for updates and new content.Let's examine the various assertion methods that are ...
Read more >
Assert method (Visual Basic for Applications) | Microsoft Learn
Assert invocations work only within the development environment. When the module is compiled into an executable, the method calls on the Debug ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found