Skip to content

Commit 5d5cf1a

Browse files
committed
Refactor pytest task: replace batch script with Python command and add custom options for window display
1 parent 58ce252 commit 5d5cf1a

File tree

4 files changed

+29
-33
lines changed

4 files changed

+29
-33
lines changed

.vscode/tasks.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,16 @@
139139
},
140140
{
141141
"label": "🚀 Run pytest",
142-
"command": "cmd",
142+
"command": "${command:python.interpreterPath}",
143143
"args": [
144-
"/c",
145-
"run_pytest.bat"
144+
"-m",
145+
"pytest",
146+
"--ff",
146147
],
147148
"options": {
148-
"cwd": "scripts",
149+
"cwd": "${workspaceFolder}",
149150
"env": {
150-
"UNATTENDED": "1",
151-
"PYTHON": "${command:python.interpreterPath}"
151+
"UNATTENDED": "1"
152152
}
153153
},
154154
"group": {
@@ -158,9 +158,12 @@
158158
"presentation": {
159159
"echo": true,
160160
"reveal": "always",
161+
"focus": false,
162+
"panel": "dedicated",
161163
"showReuseMessage": true,
164+
"clear": true
162165
},
163-
"type": "shell"
166+
"type": "shell",
164167
},
165168
{
166169
"label": "Update requirements.txt",

plotpy/tests/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# content of conftest.py
22

33
import gc
4+
import os
45

56
import guidata
67
import h5py
@@ -20,6 +21,22 @@
2021
execenv.verbose = "quiet"
2122

2223

24+
def pytest_addoption(parser):
25+
"""Add custom command line options to pytest."""
26+
parser.addoption(
27+
"--show-windows",
28+
action="store_true",
29+
default=False,
30+
help="Display Qt windows during tests (disables QT_QPA_PLATFORM=offscreen)",
31+
)
32+
33+
34+
def pytest_configure(config):
35+
"""Configure pytest based on command line options."""
36+
if not config.getoption("--show-windows"):
37+
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
38+
39+
2340
@pytest.fixture(scope="session", autouse=True)
2441
def disable_gc_for_tests():
2542
"""Disable garbage collection for all tests in the session."""

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ include = ["plotpy*"]
7777
version = { attr = "plotpy.__version__" }
7878

7979
[tool.pytest.ini_options]
80-
addopts = "plotpy"
80+
addopts = "plotpy --import-mode=importlib"
81+
# addopts = "plotpy --import-mode=importlib --show-windows" # Disable offscreen mode
8182

8283
[tool.ruff]
8384
exclude = [".git", ".vscode", "build", "dist"]

scripts/run_pytest.bat

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)