Skip to content

Demo mode crashes with ModuleNotFoundError: No module named 'pytest' in MSI-installed builds #365

Description

@ThomasMalletCodra

Describe the bug

In a DataLab instance installed via the MSI installer (frozen/PyInstaller build), triggering Demo mode (toolbar action or menu entry) crashes with a traceback instead of running the demo scenario:

Traceback (most recent call last):
  File "guidata\qthelpers.py", line 377, in <lambda>
  File "datalab\gui\main.py", line 2308, in play_demo
  File "pyimod02_importers.py", line 457, in exec_module
  File "datalab\tests\__init__.py", line 33, in <module>
ModuleNotFoundError: No module named 'pytest'

Root cause (identified in code)

DLMainWindow.play_demo() in datalab/gui/main.py (line 2304) calls
datalab.tests.scenarios.demo.play_demo(), which does
from datalab.tests import datalab_test_app_context (datalab/tests/scenarios/demo.py,
line 31). This triggers the import of datalab/tests/__init__.py, which has
import pytest at module level (line 33).

Since pytest is a test-only dependency, it is not bundled by PyInstaller in the
MSI/standalone build, so any code path that imports datalab.tests (even indirectly,
just to reuse the demo/test-context helper) fails at runtime in frozen installations.

To Reproduce

  1. Install DataLab using the official MSI installer (not from a development/pip
    environment with pytest available).
  2. Launch DataLab.
  3. Trigger Demo mode (toolbar action or menu entry calling play_demo).
  4. Observe the ModuleNotFoundError: No module named 'pytest' traceback (visible in
    the console, or via the error dialog/log).

Expected behavior

The Demo mode should run correctly in installed/frozen builds, without requiring
pytest (a development/test dependency) to be present.

Environment

  • Installation type: MSI installer (frozen/PyInstaller build)
  • Affected versions: 1.1.0, 1.2.2, 1.3.0 (confirmed on multiple releases — long-standing
    regression)
  • OS: Windows

Possible fix directions

  • Decouple datalab.tests.scenarios.demo from datalab.tests.__init__ (e.g., move
    datalab_test_app_context to a module that doesn't import pytest), or
  • Make the pytest import in datalab/tests/__init__.py lazy/optional, or
  • Bundle pytest as a hidden import in the PyInstaller spec (less desirable, increases
    installer size for a test-only dependency).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions