Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2473

Importing PySide6 breaks using unittest.mock.patch.dict to mock imports

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3: Somewhat important P3: Somewhat important
    • 6.6.0
    • 6.5.0, 6.4.2
    • PySide, Shiboken
    • None
    • All
    • 4ae031947 (dev), 1b9c1fcb4 (6.6), 15e0392ce (6.5)

      The Python standard library's built-in `unittest.mock.patch.dict` feature allows temporarily replacing a module with a mock at import-time, as described at https://docs.python.org/3/library/unittest.mock-examples.html#mocking-imports-with-patch-dict

      However, once PySide6 has been imported, trying to use this feature raises AttributeError: __name__ when shibokensupport/feature.py:feature_imported() tries to access __name__ on the mocked module during import.

      A similar bug, PYSIDE-1368, was reported and fixed in feature_import() by "feature: ignore if `__name__` does not exist in a module" d02b070e23c757fa72a66a4049a659f4f5c5fc77 https://codereview.qt-project.org/c/pyside/pyside-setup/+/312517 , but it doesn't look like the solution was carried forward into the new code added in commit "feature: heavily rework the context switching" 7377d2b8130ce7290775cd8a343e75c0561fc854 https://codereview.qt-project.org/c/pyside/pyside-setup/+/444454. Perhaps an analogous fix could work here, replacing module.__name__ with getattr(module, '__name__', '__main__')?

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            kleint Friedemann Kleint
            dennis_sparkcharge Dennis Lambe
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes