Skip to content

Fix integration test failures caused by sys.modules pollution and shutil.SameFileError#349

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-integration-tests-failure
Draft

Fix integration test failures caused by sys.modules pollution and shutil.SameFileError#349
Copilot wants to merge 4 commits intomainfrom
copilot/fix-integration-tests-failure

Conversation

Copy link
Contributor

Copilot AI commented Mar 5, 2026

Two test files were replacing sys.modules['streamlit'] and sys.modules['pyopenms'] with MagicMocks at module level, causing pytest to poison the global module registry during collection — before any tests ran. This broke all test_gui.py AppTest runs with ModuleNotFoundError: No module named 'streamlit.emojis'; 'streamlit' is not a package. A separate shutil.SameFileError caused test failures when symlinks created by test_file_upload_load_example were re-copied in subsequent tests.

Changes

  • tests/test_parameter_presets.py — Removed the unnecessary pyopenms mock. The streamlit mock is still needed because ParameterManager imports streamlit at the top level and the tests need st.session_state to be a controllable plain dict for unit testing preset logic without a running Streamlit app context. The mock is now saved and restored immediately after importing ParameterManager, and cached src.workflow.* entries are evicted so AppTest re-imports them with the real package:

    _original_streamlit = sys.modules.get('streamlit')
    sys.modules['streamlit'] = mock_streamlit
    from src.workflow.ParameterManager import ParameterManager
    # Restore so test_gui.py AppTests get the real streamlit
    sys.modules['streamlit'] = _original_streamlit  # (or pop if was absent)
    for _key in list(sys.modules.keys()):
        if _key.startswith('src.workflow'):
            sys.modules.pop(_key, None)
  • tests/test_topp_workflow_parameter.py — Removed all module-level mocks entirely. The tests use pure MagicMock objects and don't import any src.* modules, so the pyopenms mock served no purpose. Also removed the test_mock_pyopenms test that only verified the mock was working.

  • test_gui.py — Catch shutil.SameFileError when copying example mzML files into the workspace. On Linux, load_example_mzML_files() creates symlinks pointing back to the same source files, so a subsequent shutil.copy raises SameFileError:

    for f in Path("example-data", "mzML").glob("*.mzML"):
        try:
            shutil.copy(f, mzML_dir)
        except shutil.SameFileError:
            pass  # already exists as a symlink to the same source
  • .github/workflows/ci.yml — Replace conda-incubator/setup-miniconda + conda install openms with actions/setup-python@v4. pyopenms is already a standalone PyPI package in requirements.txt; the conda layer was redundant and conflicted with the pip-installed streamlit.

  • .github/workflows/build-windows-executable-app.yaml — Fix the "Clean up unnecessary Python files" step which used a hardcoded wrong path py/Lib/site-packages instead of python-${{ env.PYTHON_VERSION }}/Lib/site-packages, matching the path used by the "Install Required Packages" step.

Original prompt

This section details on the original issue you should resolve

<issue_title>Integration Tests are failing.</issue_title>
<issue_description>continuous-integration / test (ubuntu-latest, 3.11) (push)
continuous-integration / test (ubuntu-latest, 3.11) (push)Failing after 2m
Test workflow functions / build (pull_request)
Test workflow functions / build (pull_request)Failing after 1m</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…FileError, update CI workflow

Co-authored-by: t0mdavid-m <57191390+t0mdavid-m@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix integration tests that are failing Fix integration test failures caused by sys.modules pollution and shutil.SameFileError Mar 5, 2026
@t0mdavid-m
Copy link
Member

@copilot Why do we need mocks here?

…, simplify test_parameter_presets.py

Co-authored-by: t0mdavid-m <57191390+t0mdavid-m@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 5, 2026

@copilot Why do we need mocks here?

The pyopenms mock in test_topp_workflow_parameter.py wasn't needed — the tests use pure MagicMock objects and don't import any src.* modules. Removed it entirely in c3715d1.

In test_parameter_presets.py, the streamlit mock is still needed: ParameterManager does import streamlit as st at the top level, and the tests need st.session_state to be a controllable plain dict (for testing apply_preset, clear_parameter_session_state, etc.) without requiring a running Streamlit app context. Removed the unnecessary pyopenms mock from there too.

@t0mdavid-m
Copy link
Member

@copilot fix the error in the windows build

Co-authored-by: t0mdavid-m <57191390+t0mdavid-m@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 6, 2026

@copilot fix the error in the windows build

The "Clean up unnecessary Python files" step in build-windows-executable-app.yaml used a hardcoded path py/Lib/site-packages that doesn't exist — the embeddable Python is installed at python-3.11.0/Lib/site-packages. Fixed the path to use python-${{ env.PYTHON_VERSION }}/Lib/site-packages to match the install step on line 246. This was a pre-existing bug, not introduced by my changes. Fixed in 6af0435.

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

Successfully merging this pull request may close these issues.

Integration Tests are failing.

2 participants