Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mihail12101 opened this issue Dec 21, 2020 · 1 comment

Comments

@mihail12101
Copy link

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!

@h2non
Copy link
Member

h2non commented Dec 22, 2020

Perhaps @sgissinger can help faster here. I'm quite busy lately.

sgissinger added a commit to sgissinger/grappa that referenced this issue Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants