Blue Otter Hat
Blue Otter Hat

Reputation: 617

Using assert statements only through Microsoft Nutter to unit test raised exception in Databricks notebooks

I am using the MS Nutter framework to unit test python functions written in Databricks notebooks, https://github.com/microsoft/nutter.

One function raises a ValueError exception. How do I test for this correctly via Nutter?

Nutter only seems to include assert commands, nothing like with pytest.raises(ValueError). Is there a workaround to use assert to test exceptions? Or is there part of Nutter that I have not discovered that allows for this?

Upvotes: 0

Views: 575

Answers (2)

AutomationTester
AutomationTester

Reputation: 31

Elaborating Fabrice answer (Hope it helps):

def assertion_valuerrorcheck():
   try:
      valueErrorFlag = False
      try:
         #code which raises value error
      except ValueError:
         valueErrorFlag = True
      assert(valueErrorFlag) #if True, case is passed
   except AssertionError:
         #print why assertion failed

Upvotes: 1

fabrice deseyn
fabrice deseyn

Reputation: 1

You could use exception-handling in the run-function to set a flag and use the assertion to identify if the flag is set.

Upvotes: 0

Related Questions