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

logging.error calls from non-robot code are treated as robot errors #300

Open
anandautam1 opened this issue Aug 13, 2024 · 3 comments
Open

Comments

@anandautam1
Copy link

anandautam1 commented Aug 13, 2024

Exception thrown from another import is not being suppressed when calling pytest.raises
I tested the scenario where a module right away throwing the import - and that works fine

OS: Running on windows

requirements:

python-can==3.3.4
pytest_robotframework==4.2.3

import can
import pytest
from robot.errors import HandlerExecutionFailed

def test_exception_from_other_module():
    with pytest.raises(OSError):
        bus = can.ThreadSafeBus(app_name='dummy', channel='vcan0', bustype='socketcan')

Without pytest_robotframework installed i dont get a failure

With pytest_robotframework installed i failed

I got:

================================== FAILURES ===================================
______________________ test_exception_from_other_module _______________________
robot errors occurred and were caught by pytest-robotframework:

- fcntl not available on this platform
---------------------------- Captured stderr call -----------------------------
[ ERROR ] fcntl not available on this platform
[ WARN ] libc is unavailable
------------------------------ Captured log call ------------------------------
ERROR    can.interfaces.socketcan.socketcan:socketcan.py:22 fcntl not available on this platform
WARNING  can.interfaces.socketcan.socketcan:socketcan.py:55 libc is unavailable
@anandautam1 anandautam1 changed the title Exception thrown from another import is not being supressed when calling pytest.raises pytest.raises does not suppress exception thrown from another import Aug 13, 2024
@anandautam1
Copy link
Author

@DetachHead could you help me investigate ?

@DetachHead
Copy link
Owner

DetachHead commented Aug 14, 2024

so it looks like what's happening here is:

  1. the can module calls logging.error with that message
  2. robotframework seems to listen for logging.error calls and reports them as robot errors
  3. since robot internal errors and errors from listeners are handled by robot in the exact same way, pytest-robotframework has checks to listen for robot errors and raise an exception at the end of the pytest session if any occurred

robot handles errors in the stupidest way imaginable. ideally there'd be a way to differentiate random logging.error calls from internal errors that come from robot itself. not sure what the best way to fix this would be unfortunately

@DetachHead DetachHead changed the title pytest.raises does not suppress exception thrown from another import logging.error calls from non-robot code are treated as robot errors Aug 14, 2024
@anandautam1
Copy link
Author

@DetachHead can we detect whether the logging.error is actually within a pytest.raises and not taken account the logging.error from that section of the robot log ? i'm not quite sure how deep the pytest listener is actually being implemented.

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

No branches or pull requests

2 participants