I need help in testing at unit test level RIDE, to increase code coverage and have green status at SonarCloud .
I wrote a small Medium post to point to the GitHub project I have prepared to reproduce the problem and motivate programmers to help me.
Basically:
I am stuck at one test that validates the block of code which imports wxPython and should fail if there are problems with it.
This is the block to test:
try:
import wx
import wx.lib.inspection
except ModuleNotFoundError:
print("ERROR: App cannot proceed, because wx is missing!")
sys.exit(1)
And this is the code to test it (at least one of the many versions I tried):
import unittest
import pytest
from pytest import MonkeyPatch
import builtins
real_import = builtins.__import__
def myimport(name, globals, locals, fromlist, level):
# DEBUG print(f"DEBUG: called myimport! name={name}")
if name == 'wx.lib.inspection':
raise ModuleNotFoundError # real_import('wx_error', globals, locals, fromlist, level)
# raise ImportError
return real_import(name, globals, locals, fromlist, level)
class TestModule(unittest.TestCase):
def tearDown(self):
builtins.__import__ = real_import
def test_missing_wx(self):
with MonkeyPatch().context() as m:
with pytest.raises((ModuleNotFoundError, SystemExit)):
builtins.__import__ = myimport
import myapp
print(myapp.m1.VERSION)
print(dir(myapp.m1))