Skip to content

should.do_not.raise_error() crashes while using function without raising exception #68

@mihail12101

Description

@mihail12101

Hello.

In case when we want to check that our function will not raise some exception and our function will not raise any exceptions
grappa crashes with error.

Python 3.7
grappa v1.0.1

See example below:

Example from grappa test-suite: tests/operators/raises_test.py

def test_raises(should):
    def no_error():
        pass

    # This case is absent in grappa test-suite
    no_error | should.do_not.raise_error(NotImplementedError)

Error:

Traceback (most recent call last):
  File "C:\Users\MKalistratov\AppData\Roaming\Python\Python37\site-packages\grappa\runner.py", line 62, in run
    return self.run_assertions(ctx)
  File "C:\Users\MKalistratov\AppData\Roaming\Python\Python37\site-packages\grappa\runner.py", line 30, in run_assertions
    result = assertion(ctx.subject)
  File "C:\Users\MKalistratov\AppData\Roaming\Python\Python37\site-packages\grappa\resolver.py", line 54, in assertion
    return operator.run(subject, *expected, **kw)
  File "C:\Users\MKalistratov\AppData\Roaming\Python\Python37\site-packages\grappa\operator.py", line 209, in run
    return self.run_matcher(*args, **kw)
  File "C:\Users\MKalistratov\AppData\Roaming\Python\Python37\site-packages\grappa\operator.py", line 148, in observer
    self.after_success(subject, *expected, **kw)
  File "C:\Users\MKalistratov\AppData\Roaming\Python\Python37\site-packages\grappa\operators\raises.py", line 62, in after_success
    message = ' '.join([str(item) for item in self.value.args])
AttributeError: 'Empty' object has no attribute 'args'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:/Users/MKalistratov/.PyCharmCE2019.3/config/scratches/scratch.py", line 6, in <module>
    no_error | should.do_not.raise_error(NotImplementedError)
  File "C:\Users\MKalistratov\AppData\Roaming\Python\Python37\site-packages\grappa\test.py", line 208, in __ror__
    return self.__overload__(value)
  File "C:\Users\MKalistratov\AppData\Roaming\Python\Python37\site-packages\grappa\test.py", line 196, in __overload__
    return self.__call__(subject, overload=True)
  File "C:\Users\MKalistratov\AppData\Roaming\Python\Python37\site-packages\grappa\test.py", line 73, in __call__
    return self._trigger() if overload else Test(subject)
  File "C:\Users\MKalistratov\AppData\Roaming\Python\Python37\site-packages\grappa\test.py", line 113, in _trigger
    raise err
AssertionError: Oops! Something went wrong!

Looks like function def match (line 66) in file: \operators\raises.py has no statements to handle case when function will not raise any exception and self.value will not set

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions