Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest exits with null code and SIGSEGV #22776

Closed
cedev-lmat opened this issue Jan 23, 2024 · 5 comments
Closed

pytest exits with null code and SIGSEGV #22776

cedev-lmat opened this issue Jan 23, 2024 · 5 comments
Assignees
Labels
area-testing triage-needed Needs assignment to the proper sub-team

Comments

@cedev-lmat
Copy link

cedev-lmat commented Jan 23, 2024

Type: Bug

Behaviour

Expected vs. Actual

Expected: The extension to be able to detect tests when pytest test discovery succeeds.

Actual: Running ./.venvs/bin/python -m pytest --collect-only works perfectly. Refresh the tests from the button works but I have an error message in the python log and there the "pytest Discovery Error" banner in the testing tab. I can run the test with debugging and it detects as successful. When I run the test without debugging, it detects it as failed with the [error] Subprocess exited unsuccessfully with exit code null and signal SIGSEGV on workspace ... error message

Steps to reproduce:

  1. pyproject.toml
[tool.pytest.ini_options]
minversion = "7.4"
#addopts = "-ra -q"
cache_dir = ".caches/pytest"
#log_auto_indent = true
testpaths = [
  "tests",
]
  1. settings.json
{
    "testing.defaultGutterClickAction": "debug",
    "python.languageServer": "Pylance",
    "python.testing.autoTestDiscoverOnSaveEnabled": false,
    "python.testing.unittestEnabled": false,
    "python.testing.pytestEnabled": true,
}
  1. launch.json
{
    "version": "0.1.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true
        },
    ]
}
  1. Layout
  • module in ./src/ folder
  • tests in ./tests/ folder
  1. Click on the

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.12.0
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Pylance
Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

2024-01-23 11:16:13.227 [info] Running installed packages checker:  /Users/USERNAME/Desktop/python_hatch_template/.venvs/bin/python /Users/USERNAME/.vscode/extensions/ms-python.python-2023.22.1/pythonFiles/installed_check.py /Users/USERNAME/Desktop/python_hatch_template/pyproject.toml
2024-01-23 11:16:13.227 [info] > ./.venvs/bin/python ~/.vscode/extensions/ms-python.python-2023.22.1/pythonFiles/installed_check.py ./pyproject.toml
2024-01-23 11:16:14.660 [info] Discover tests for workspace name: python_hatch_template - uri: /Users/USERNAME/Desktop/python_hatch_template
2024-01-23 11:16:14.660 [info] Running discovery for pytest using the new test adapter.
2024-01-23 11:16:14.660 [info] All environment variables set for pytest discovery for workspace /Users/USERNAME/Desktop/python_hatch_template: {"COMMAND_MODE":"unix2003","HOME":"/Users/USERNAME","LOGNAME":"USERNAME","MallocNanoZone":"0","OLDPWD":"/","ORIGINAL_XDG_CURRENT_DESKTOP":"undefined","PWD":"/","SHELL":"/bin/zsh","SHLVL":"0","SSH_AUTH_SOCK":"/private/tmp/com.apple.launchd.DuUnRoJfbQ/Listeners","TMPDIR":"/var/folders/mc/81l0rqld58q52s3gbgrrz1780000gn/T/","USER":"USERNAME","VSCODE_AMD_ENTRYPOINT":"vs/workbench/api/node/extensionHostProcess","VSCODE_CODE_CACHE_PATH":"/Users/USERNAME/Library/Application Support/Code/CachedData/8b3775030ed1a69b13e4f4c628c612102e30a681","VSCODE_CRASH_REPORTER_PROCESS_TYPE":"extensionHost","VSCODE_CWD":"/","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","VSCODE_IPC_HOOK":"/Users/USERNAME/Library/Application Support/Code/1.85-main.sock","VSCODE_NLS_CONFIG":"{\"locale\":\"en-gb\",\"osLocale\":\"en-gb\",\"availableLanguages\":{},\"_languagePackSupport\":true}","VSCODE_PID":"14639","XPC_FLAGS":"0x0","XPC_SERVICE_NAME":"application.com.microsoft.VSCode.90466387.90466393","_":"/Applications/Visual Studio Code.app/Contents/MacOS/Electron","__CFBundleIdentifier":"com.microsoft.VSCode","__CF_USER_TEXT_ENCODING":"0x1F5:0x0:0x2","ELECTRON_RUN_AS_NODE":"1","VSCODE_L10N_BUNDLE_LOCATION":"","PATH":"/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Pololu USB AVR Programmer v2.app/Contents/MacOS","PYTHONPATH":"/Users/USERNAME/.vscode/extensions/ms-python.python-2023.22.1/pythonFiles","TEST_UUID":"ecfbe987-9103-441a-aff7-d2dc1ff42c5a","TEST_PORT":"62079"} 

2024-01-23 11:16:14.680 [info] > ./.venvs/bin/python -m pytest -p vscode_pytest --collect-only
2024-01-23 11:16:14.680 [info] cwd: .
2024-01-23 11:16:15.322 [info] tests/test_Cli.py::test_version
tests/test_Demo.py::test_initialization
tests/test_Demo.py::test_failing_test
tests/test_Demo.py::test_equality
tests/test_Demo.py::test_STR
tests/test_Demo.py::test_REPR
tests/test_Demo.py::test_neverrun

2024-01-23 11:16:15.329 [info] Test server connected to a client.
2024-01-23 11:16:15.331 [info] ResultResolver EOT received for discovery.
2024-01-23 11:16:15.332 [info] 

2024-01-23 11:16:15.333 [info] 7 tests collected in 0.03s

2024-01-23 11:16:15.674 [error] Subprocess exited unsuccessfully with exit code null and signal SIGSEGV on workspace /Users/USERNAME/Desktop/python_hatch_template.
2024-01-23 11:16:15.675 [error] Subprocess exited unsuccessfully with exit code null and signal SIGSEGV on workspace /Users/USERNAME/Desktop/python_hatch_template. Creating and sending error discovery payload
2024-01-23 11:16:15.675 [error] pytest test discovery error for workspace:  /Users/USERNAME/Desktop/python_hatch_template 
  
 The python test process was terminated before it could exit on its own, the process errored with: Code: null, Signal: SIGSEGV for workspace /Users/USERNAME/Desktop/python_hatch_template
2024-01-23 11:16:15.675 [info] ResultResolver EOT received for discovery.
2024-01-23 11:16:15.676 [info] Disposing data receiver for /Users/USERNAME/Desktop/python_hatch_template and deleting UUID; pytest discovery.

User Settings


languageServer: "Pylance"

testing
• pytestEnabled: true
• autoTestDiscoverOnSaveEnabled: false

Extension version: 2023.22.1
VS Code version: Code 1.85.2 (8b3775030ed1a69b13e4f4c628c612102e30a681, 2024-01-18T06:40:32.531Z)
OS version: Darwin x64 21.6.0
Modes:

System Info
Item Value
CPUs Intel(R) Core(TM) i7-5650U CPU @ 2.20GHz (4 x 2200)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 12, 6, 5
Memory (System) 8.00GB (0.02GB free)
Process Argv --crash-reporter-id 37fa9bf6-f598-4ac4-93e2-253afd6e2e6e
Screen Reader no
VM 0%
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Jan 23, 2024
@cedev-lmat
Copy link
Author

Problem is in my setup sorry

@eleanorjboyd
Copy link
Member

No worries! Happy coding! (If you do have a moment to comment the fix other users who run into the same setup issue could reference this for help)

@eleanorjboyd eleanorjboyd closed this as not planned Won't fix, can't repro, duplicate, stale Jan 25, 2024
@cedev-lmat
Copy link
Author

I managed to understand where the problem is coming from but haven't found a proper solution yet.

TL;DR

The workspace error is caused by the import hatchdemo import statement in the ./tests/test_GUI.py file.

My guess is that the paths are not correctly set for the tests discovery.
What is your opinion? A solution?

(Sorry for the long post)

Description

If I run the discovery manually via hatch run test:discover, it runs fine

Click me ``` >> hatch run test:discover cmd [1] | pytest --collect-only ========================================================= test session starts ========================================================= platform darwin -- Python 3.12.0, pytest-7.4.4, pluggy-1.4.0 cachedir: .caches/pytest rootdir: /Users/USER/Desktop/hatchmwe configfile: pyproject.toml testpaths: tests plugins: xdist-3.5.0 collected 1 item
<Package tests>
<Module test_GUI.py>
    <Function test_gui_wait>

====================================================== 1 test collected in 2.35s ======================================================
```

Whereas in my testing tab, I have the pytest discovery error if I try to refresh tests and I have the following in the python output:

Click me ``` 2024-01-25 21:16:50.177 [info] Running discovery for pytest using the new test adapter. 2024-01-25 21:16:50.177 [info] All environment variables set for pytest discovery for workspace /Users/USER/Desktop/hatchmwe: {"COMMAND_MODE":"unix2003","HOME":"/Users/USER","LOGNAME":"USER","MallocNanoZone":"0","OLDPWD":"/","ORIGINAL_XDG_CURRENT_DESKTOP":"undefined","PWD":"/","SHELL":"/bin/zsh","SHLVL":"0","SSH_AUTH_SOCK":"/private/tmp/com.apple.launchd.DuUnRoJfbQ/Listeners","TMPDIR":"/var/folders/mc/81l0rqld58q52s3gbgrrz1780000gn/T/","USER":"USER","VSCODE_AMD_ENTRYPOINT":"vs/workbench/api/node/extensionHostProcess","VSCODE_CODE_CACHE_PATH":"/Users/USER/Library/Application Support/Code/CachedData/8b3775030ed1a69b13e4f4c628c612102e30a681","VSCODE_CRASH_REPORTER_PROCESS_TYPE":"extensionHost","VSCODE_CWD":"/","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","VSCODE_IPC_HOOK":"/Users/USER/Library/Application Support/Code/1.85-main.sock","VSCODE_NLS_CONFIG":"{\"locale\":\"en-gb\",\"osLocale\":\"en-gb\",\"availableLanguages\":{},\"_languagePackSupport\":true}","VSCODE_PID":"50854","XPC_FLAGS":"0x0","XPC_SERVICE_NAME":"application.com.microsoft.VSCode.90466387.90466393","_":"/Applications/Visual Studio Code.app/Contents/MacOS/Electron","__CFBundleIdentifier":"com.microsoft.VSCode","__CF_USER_TEXT_ENCODING":"0x1F5:0x0:0x2","ELECTRON_RUN_AS_NODE":"1","VSCODE_L10N_BUNDLE_LOCATION":"","PATH":"/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Pololu USB AVR Programmer v2.app/Contents/MacOS","PYTHONPATH":"/Users/USER/.vscode/extensions/ms-python.python-2023.22.1/pythonFiles","TEST_UUID":"c87431cf-1477-4b03-904d-1bb316c91fe0","TEST_PORT":"60259"}
2024-01-25 21:16:50.190 [info] > . ./.venvs/test/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2023.22.1/pythonFiles/printEnvVariables.py
2024-01-25 21:16:50.190 [info] shell: bash
2024-01-25 21:16:50.368 [info] > ./.venvs/test/bin/python -m pytest -p vscode_pytest --collect-only
2024-01-25 21:16:50.368 [info] cwd: .
2024-01-25 21:16:50.847 [info] ============================= test session starts ==============================

2024-01-25 21:16:50.847 [info] platform darwin -- Python 3.12.0, pytest-7.4.4, pluggy-1.4.0

2024-01-25 21:16:50.852 [info] cachedir: .caches/pytest
rootdir: /Users/USER/Desktop/hatchmwe
configfile: pyproject.toml
testpaths: tests

2024-01-25 21:16:50.852 [info] plugins: xdist-3.5.0

2024-01-25 21:16:51.053 [info] collected 1 item

<Package tests>
<Module test_GUI.py>
2024-01-25 21:16:51.053 [info] 
    <Function test_gui_wait>

2024-01-25 21:16:51.057 [info] Test server connected to a client.
2024-01-25 21:16:51.059 [info] ResultResolver EOT received for discovery.
2024-01-25 21:16:51.059 [info] 
========================== 1 test collected in 0.21s ===========================

2024-01-25 21:16:51.271 [error] Subprocess exited unsuccessfully with exit code null and signal SIGSEGV on workspace /Users/USER/Desktop/hatchmwe.
2024-01-25 21:16:51.272 [error] Subprocess exited unsuccessfully with exit code null and signal SIGSEGV on workspace /Users/USER/Desktop/hatchmwe. Creating and sending error discovery payload
2024-01-25 21:16:51.272 [error] pytest test discovery error for workspace:  /Users/USER/Desktop/hatchmwe 

The python test process was terminated before it could exit on its own, the process errored with: Code: null, Signal: SIGSEGV for workspace /Users/USER/Desktop/hatchmwe
2024-01-25 21:16:51.272 [info] ResultResolver EOT received for discovery.
2024-01-25 21:16:51.272 [info] Disposing data receiver for /Users/USER/Desktop/hatchmwe and deleting UUID; pytest discovery.
```

Additionally when I run a test via the Run Test button, the test runs fine (everything is correct in the TEST RESULTS tab) but the workspace crashes and the test is marked as successful for 0.3s and then as failed.

Click me ``` 2024-01-25 21:38:17.261 [info] Server listening on port 64415 2024-01-25 21:38:17.269 [info] All environment variables set for pytest execution in /Users/USER/Desktop/hatchmwe workspace: {"COMMAND_MODE":"unix2003","HOME":"/Users/USER","LOGNAME":"USER","MallocNanoZone":"0","OLDPWD":"/","ORIGINAL_XDG_CURRENT_DESKTOP":"undefined","PWD":"/","SHELL":"/bin/zsh","SHLVL":"0","SSH_AUTH_SOCK":"/private/tmp/com.apple.launchd.DuUnRoJfbQ/Listeners","TMPDIR":"/var/folders/mc/81l0rqld58q52s3gbgrrz1780000gn/T/","USER":"USER","VSCODE_AMD_ENTRYPOINT":"vs/workbench/api/node/extensionHostProcess","VSCODE_CODE_CACHE_PATH":"/Users/USER/Library/Application Support/Code/CachedData/8b3775030ed1a69b13e4f4c628c612102e30a681","VSCODE_CRASH_REPORTER_PROCESS_TYPE":"extensionHost","VSCODE_CWD":"/","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","VSCODE_IPC_HOOK":"/Users/USER/Library/Application Support/Code/1.85-main.sock","VSCODE_NLS_CONFIG":"{\"locale\":\"en-gb\",\"osLocale\":\"en-gb\",\"availableLanguages\":{},\"_languagePackSupport\":true}","VSCODE_PID":"50854","XPC_FLAGS":"0x0","XPC_SERVICE_NAME":"application.com.microsoft.VSCode.90466387.90466393","_":"/Applications/Visual Studio Code.app/Contents/MacOS/Electron","__CFBundleIdentifier":"com.microsoft.VSCode","__CF_USER_TEXT_ENCODING":"0x1F5:0x0:0x2","ELECTRON_RUN_AS_NODE":"1","VSCODE_L10N_BUNDLE_LOCATION":"","PATH":"/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Pololu USB AVR Programmer v2.app/Contents/MacOS","PYTHONPATH":"/Users/USER/.vscode/extensions/ms-python.python-2023.22.1/pythonFiles","TEST_UUID":"c8c2ca16-f001-4223-a31f-837f09e93479","TEST_PORT":"60259","RUN_TEST_IDS_PORT":"64415"} 2024-01-25 21:38:17.269 [info] Running pytest with arguments: /Users/USER/.vscode/extensions/ms-python.python-2023.22.1/pythonFiles/vscode_pytest/run_pytest_script.py --rootdir /Users/USER/Desktop/hatchmwe for workspace /Users/USER/Desktop/hatchmwe
2024-01-25 21:38:17.269 [info] > ./.venvs/test/bin/python ~/.vscode/extensions/ms-python.python-2023.22.1/pythonFiles/vscode_pytest/run_pytest_script.py --rootdir .
2024-01-25 21:38:17.269 [info] cwd: .
2024-01-25 21:38:21.012 [info] Test server connected to a client.
2024-01-25 21:38:21.016 [info] ResultResolver EOT received for execution.
2024-01-25 21:38:21.033 [info] Client disconnected
2024-01-25 21:38:21.263 [error] Subprocess exited unsuccessfully with exit code null and signal SIGSEGV on workspace /Users/USER/Desktop/hatchmwe
2024-01-25 21:38:21.265 [error] Subprocess closed unsuccessfully with exit code null and signal SIGSEGV for workspace /Users/USER/Desktop/hatchmwe. Creating and sending error execution payload 

2024-01-25 21:38:21.265 [info] ResultResolver EOT received for execution.
2024-01-25 21:38:21.265 [info] Disposing data receiver for /Users/USER/Desktop/hatchmwe and deleting UUID; pytest execution.
```

Finally when I run the same test via the Debug Test button, the test runs successfully, the workspace is fine and the test is marked as successful.

Minimal working example

Here is the full setup of my MWE. It relies on hatch and wxpython.
I'm running vscode 1.85.2 with pylance (v2023.12.1) and python (v2023.22.1) extensions installed.

Please create the environments by running these commands before testing:

hatch env create default
hatch env create test

Content of ./.vscode/settings.json

Click me ``` { "python.analysis.extraPaths": [ ".venvs/default/lib/python3.12/site-packages", ], "python.defaultInterpreterPath": "${workspaceFolder}/.venvs/test/", "python.languageServer": "Pylance", "python.terminal.activateEnvInCurrentTerminal": false, "python.terminal.activateEnvironment": false, "python.testing.pytestEnabled": true, "python.testing.pytestPath": "${workspaceFolder}/.venvs/test/bin/pytest", "python.testing.unittestEnabled": false, "testing.defaultGutterClickAction": "debug", } ```

Content of ./pyproject.toml

Click me ``` [build-system] requires = ["hatchling"] build-backend = "hatchling.build"
[project]
name = "HatchDemo"
version = "0.0.1"
requires-python = ">=3.10"
dependencies = [
"wxpython",
]

[dirs]
cache = ".caches/hatch"
[dirs.env]
virtual = ".venvs/"

[project.optional-dependencies]
test = [
"pytest",
"pytest-runner",
"pytest-xdist",
]

[tool.hatch.envs.default]
type = "virtual"
path = ".venvs/default/"
skip-install = true
[tool.hatch.envs.default.scripts]
upgrade = "PIP_COMPILE_UPGRADE='{args:1}' hatch env run --env {env_name} -- python --version"

[tool.hatch.envs.test]
path = ".venvs/test/"
skip-install = false
features = [
"test",
]
[tool.hatch.envs.test.scripts]
run = [
"pytest {args}",
]
discover = [
"pytest --collect-only {args:.}",
]

[tool.pytest.ini_options]
minversion = "7.0"
cache_dir = ".caches/pytest"
testpaths = [
"tests",
]
```

Content of ./src/hatchdemo/init.py

Click me ``` import typing
import wx


__all__ = ["startGUIsync"]

class Frame(wx.Frame):
    def __init__(
        self,
        parent: typing.Any,
        id: int = wx.ID_ANY,
        title: str = "",
        pos: wx.Point = wx.DefaultPosition,
        size: wx.Size = wx.DefaultSize,
        style: int = wx.DEFAULT_FRAME_STYLE,
    ) -> None:
        """Construct the instance.
        """
        super().__init__(
            parent=parent, id=id, title=title, pos=pos, size=size, style=style
        )

        self.SetSize(size=size)

        self.Centre(direction=wx.BOTH)

def startGUIsync(fpath: str = "") -> None:
    """Entry point for the GUI.

    This is the entry point for starting the GUI.

    :param wait: whether the app should block execution
    :type wait: bool
    :param fpath: the file path
    :type fpath: str
    """
    app = wx.App(False)

    main_frame: Frame = Frame(
        parent=None,
        title="Demo App Title",
        size=wx.Size(width=1000, height=500),
    )

    main_frame.Show()
    main_frame.Raise()
    
    app.MainLoop()
```

Content of ./tests/init.py

Click me ``` # empty ```

Content of ./tests/test_GUI.py

Click me
```
import hatchdemo

def test_gui():
    hatchdemo.startGUIsync(fpath="")

def test_donothing():
    assert True
```

PROBLEM

I can get it to work if I move the import hatchdemo statement inside the test_gui function but it don't see any reasons explaining why I should do that.

My guess is that the paths are not correctly set for the tests discovery. What is your opinion? A solution?

@eleanorjboyd
Copy link
Member

if you do python -m pytest from the terminal does that work?

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jan 25, 2024
@cedev-lmat
Copy link
Author

OK just got to the bottom of it.

It is a known problem with wxPython on python 3.12.0.
It doesn't do a proper clean up upon exit.

Solution is to accept it or use another version of python :)

Thanks

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Jan 26, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

2 participants