Skip to content

Commit 61a2731

Browse files
committed
Improve test action by using pytest-xdist
1 parent 7206f2a commit 61a2731

File tree

4 files changed

+61
-5
lines changed

4 files changed

+61
-5
lines changed

.github/workflows/test.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ defaults:
1313

1414
env:
1515
PYTHONIOENCODING: 'utf-8' # For log color
16-
PY_COLORS: 1 # For log color with pytest
16+
17+
# This enable log color of pytest.
18+
# --color=yes option is not working on GitHub Action.
19+
# See https://github.com/pytest-dev/pytest/issues/1397.
20+
PY_COLORS: 1
1721

1822
jobs:
1923
pytest:
@@ -87,7 +91,12 @@ jobs:
8791
libopengl0
8892
8993
- name: Run pytest
90-
run: poetry run pytest --cov --cov-report=term-missing --cov-report=xml
94+
run: |
95+
poetry run pytest \
96+
--cov \
97+
--cov-report=term-missing \
98+
--cov-report=xml \
99+
-n auto
91100
92101
- name: Upload coverage to Codecov
93102
uses: codecov/codecov-action@v3
@@ -150,7 +159,8 @@ jobs:
150159
--cov-report=xml \
151160
--ignore=tests/test_widget_gallery.py \
152161
--ignore=tests/test_qdarktheme_with_qt.py \
153-
-p no:pytest-qt
162+
-p no:pytest-qt \
163+
-n auto
154164
155165
- name: Upload coverage to Codecov
156166
uses: codecov/codecov-action@v3

poetry.lock

Lines changed: 37 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pytest-randomly = "^3.12.0"
5858
pytest-qt = "^4.2.0"
5959
pytest-xvfb = "^2.0.0"
6060
pytest-mock = "^3.10.0"
61+
pytest-xdist = "^3.0.2"
6162

6263
[tool.poetry.group.docs.dependencies]
6364
# Latest of Sphinx and flake8 cause dependency comflict.

tests/test_qdarktheme.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,17 @@ def test_load_stylesheet_when_failing_to_detect_system_theme(mocker) -> None:
116116
qdarktheme.load_stylesheet("auto")
117117

118118

119-
def test_clear_cache() -> None:
119+
def test_clear_cache(mocker) -> None:
120120
"""Verify `clear_cache()`."""
121+
from pathlib import Path
122+
123+
# qdarktheme cache save to system home path.
124+
# Cannot clear cache because another tests use cache in home path.
125+
# This mock make home path dummy home path.
126+
dummy_home_path = Path("__dummy")
127+
dummy_home_path.mkdir(exist_ok=True)
128+
mocker.patch("pathlib.Path.home", return_value=dummy_home_path)
129+
121130
qdarktheme.load_stylesheet()
122131
qdarktheme.clear_cache()
123132
# Test function when there is no cache.

0 commit comments

Comments
 (0)