Repository: pytest-dev/pytest-xdist
Pull request #967 (2023-11-11 15:32:45)

Add deploy instructions using the command-line


Patch:
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index 86d55d5..a1296a5 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -47,3 +47,9 @@ jobs:
         git config user.email "pytestbot@gmail.com"
         git tag --annotate --message=v${{ github.event.inputs.version }} v${{ github.event.inputs.version }} ${{ github.sha }}
         git push origin v${{ github.event.inputs.version }}
+
+    - name: GitHub Release
+      uses: softprops/action-gh-release@v1
+      with:
+        files: dist/*
+        tag_name: v${{ github.event.inputs.version }}
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 3a0fe32..d6328b5 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -5,7 +5,7 @@ repos:
     -   id: autoflake
         args: ["--in-place", "--remove-unused-variables", "--remove-all-unused-imports"]
 -   repo: https://github.com/psf/black
-    rev: 23.10.1
+    rev: 23.11.0
     hooks:
     -   id: black
         args: [--safe, --quiet, --target-version, py35]
@@ -39,7 +39,7 @@ repos:
         language: python
         additional_dependencies: [pygments, restructuredtext_lint]
 -   repo: https://github.com/pre-commit/mirrors-mypy
-    rev: v1.6.1
+    rev: v1.7.1
     hooks:
     -   id: mypy
         files: ^(src/|testing/)
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 2313808..0228684 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,3 +1,27 @@
+pytest-xdist 3.5.0 (2023-11-21)
+===============================
+
+Features
+--------
+
+- `#632 <https://github.com/pytest-dev/pytest-xdist/issues/632>`_: ``--dist=loadscope`` now sorts scopes by number of tests to assign largest scopes early -- in many cases this should improve overall test session running time, as there is less chance of a large scope being left to be processed near the end of the session, leaving other workers idle.
+
+
+pytest-xdist 3.4.0 (2023-11-11)
+===============================
+
+Features
+--------
+
+- `#963 <https://github.com/pytest-dev/pytest-xdist/issues/963>`_: Wait for workers to finish reporting when test run stops early.
+
+  This makes sure that the results of in-progress tests are displayed.
+  Previously these reports were being discarded, losing information about the
+  test run.
+
+- `#965 <https://github.com/pytest-dev/pytest-xdist/issues/965>`_: Added support for Python 3.12.
+
+
 pytest-xdist 3.3.1 (2023-05-19)
 ===============================
 
diff --git a/RELEASING.rst b/RELEASING.rst
index 62ce003..7ddb099 100644
--- a/RELEASING.rst
+++ b/RELEASING.rst
@@ -34,6 +34,8 @@ To publish a new release ``X.Y.Z``, the steps are as follows:
 
 #. Commit and push the branch to ``upstream`` and open a PR.
 
-#. Once the PR is **green** and **approved**, start the ``deploy`` workflow manually from the branch ``release-VERSION``, passing ``VERSION`` as parameter.
+#. Once the PR is **green** and **approved**, start the ``deploy`` workflow manually from the branch ``release-VERSION``, passing ``VERSION`` as parameter, or execute::
+
+   gh workflow run deploy.yml -R pytest-dev/pytest-xdist --ref release-X.Y.Z --field version=X.Y.Z
 
 #. Merge the release PR to ``master``.
diff --git a/changelog/963.improvement.rst b/changelog/963.improvement.rst
deleted file mode 100644
index 6cf96e2..0000000
--- a/changelog/963.improvement.rst
+++ /dev/null
@@ -1,5 +0,0 @@
-Wait for workers to finish reporting when test run stops early.
-
-This makes sure that the results of in-progress tests are displayed.
-Previously these reports were being discarded, losing information about the
-test run.
diff --git a/setup.cfg b/setup.cfg
index 77346ad..8e420ae 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -30,6 +30,7 @@ classifiers =
     Programming Language :: Python :: 3.9
     Programming Language :: Python :: 3.10
     Programming Language :: Python :: 3.11
+    Programming Language :: Python :: 3.12
 license_file = LICENSE
 project_urls =
     Documentation=https://pytest-xdist.readthedocs.io/en/latest
diff --git a/src/xdist/scheduler/loadscope.py b/src/xdist/scheduler/loadscope.py
index 35a9ef3..bcfe11f 100644
--- a/src/xdist/scheduler/loadscope.py
+++ b/src/xdist/scheduler/loadscope.py
@@ -350,11 +350,18 @@ class LoadScopeScheduling:
             return
 
         # Determine chunks of work (scopes)
+        unsorted_workqueue = OrderedDict()
         for nodeid in self.collection:
             scope = self._split_scope(nodeid)
-            work_unit = self.workqueue.setdefault(scope, default=OrderedDict())
+            work_unit = unsorted_workqueue.setdefault(scope, default=OrderedDict())
             work_unit[nodeid] = False
 
+        # Insert tests scopes into work queue ordered by number of tests.
+        for scope, nodeids in sorted(
+            unsorted_workqueue.items(), key=lambda item: -len(item[1])
+        ):
+            self.workqueue[scope] = nodeids
+
         # Avoid having more workers than work
         extra_nodes = len(self.nodes) - len(self.workqueue)
 
diff --git a/tox.ini b/tox.ini
index b0de653..ca1310a 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,7 +1,7 @@
 [tox]
 envlist=
   linting
-  py{37,38,39,310,311}-pytestlatest
+  py{37,38,39,310,311,312}-pytestlatest
   py310-pytestmain
   py310-psutil
   py310-setproctitle


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 7288c6f..fa16826 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -38,9 +38,9 @@ jobs:
           - "py38-pytestlatest"
           - "py39-pytestlatest"
           - "py310-pytestlatest"
-          - "py310-pytestmain"
           - "py311-pytestlatest"
           - "py311-pytestmain"
+          - "py312-pytestlatest"
           - "py310-psutil"
           - "py310-setproctitle"
 
@@ -54,12 +54,12 @@ jobs:
             python: "3.9"
           - tox_env: "py310-pytestlatest"
             python: "3.10"
-          - tox_env: "py310-pytestmain"
-            python: "3.10"
           - tox_env: "py311-pytestlatest"
             python: "3.11"
           - tox_env: "py311-pytestmain"
             python: "3.11"
+          - tox_env: "py312-pytestlatest"
+            python: "3.12"
           - tox_env: "py310-psutil"
             python: "3.10"
           - tox_env: "py310-setproctitle"
diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py
index 60edd9c..7b83f02 100644
--- a/testing/acceptance_test.py
+++ b/testing/acceptance_test.py
@@ -1232,6 +1232,22 @@ class TestLoadScope:
             "test_a.py::TestB", result.outlines
         ) in ({"gw0": 10}, {"gw1": 10})
 
+    def test_workqueue_ordered_by_size(self, pytester: pytest.Pytester) -> None:
+        test_file = """
+            import pytest
+            @pytest.mark.parametrize('i', range({}))
+            def test(i):
+                pass
+        """
+        pytester.makepyfile(test_a=test_file.format(10), test_b=test_file.format(20))
+        result = pytester.runpytest("-n2", "--dist=loadscope", "-v")
+        assert get_workers_and_test_count_by_prefix(
+            "test_a.py::test", result.outlines
+        ) == {"gw1": 10}
+        assert get_workers_and_test_count_by_prefix(
+            "test_b.py::test", result.outlines
+        ) == {"gw0": 20}
+
     def test_module_single_start(self, pytester: pytest.Pytester) -> None:
         """Fix test suite never finishing in case all workers start with a single test (#277)."""
         test_file1 = """