Some of our test cases break when run locally with Python >= 3.11 [1], specifically tests for our scripts. [1] To our knowlege, did not test further back. The root cause for this is that we are importing scripts with "-", and imports in python may not have "-" in their names. We believe that the unittest-module in older Python versions (e.g. 3.6) let this pass.
We need to replace "-" with e.g. "_", but not everywhere. Lines like these need to remain consistent with the file hyphenated filename we are importing and testing ("tl-script-name" as an example): > fn = os.path.join(testdir, "..", "scripts", "tl-script-name") > loader = SourceFileLoader("tl-script-name", fn) > spec = importlib.util.spec_from_loader("tl-script-name", loader) > script = importlib.util.module_from_spec(spec) > spec.loader.exec_module(script) But all other instances of "tl-script-name" need to be replaced with "tl_script_name": > sys.modules["tl_mount_localdrives"] = script > [...] > with patch("tl_script_name.SomeClass", MagicMock()) as some_mock: > script.main()
There are also some instances of > @patch("tl-script-name.open", ... ) where we could simply change the call to > @patch("builtins.open", ... ) This would make it clearer that we are in fact mocking a built-in function.