Repository: bancaditalia/black-it (language: python)

Issue:
RuntimeError on CI when running Tox on Windows, even if tests succeed
Sometimes the `tox` command fails on CI when run on Windows, e.g. see https://github.com/bancaditalia/black-it/actions/runs/6051431578/job/16422861344:

```
=== 87 passed, 19 skipped, 1 deselected, 218 warnings in 188.28s (0:03:08) ====
Traceback (most recent call last):
.pkg: _exit> python C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\site-packages\pyproject_api\_backend.py True poetry.core.masonry.api
  File "C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\site-packages\tox\session\cmd\run\single.py", line 105, in run_command_set
    current_outcome = tox_env.execute(
RuntimeError: <_overlapped.Overlapped object at 0x00000168A4752F70> still has pending operation at deallocation, the process may crash
  py310: OK (350.94=setup[159.83]+cmd[191.11] seconds)
  congratulations :) (353.58 seconds)
Error: Process completed with exit code 1.
```

Probably it is an `asyncio` issue inside `tox`, as shown here for a similar error: https://stackoverflow.com/questions/69833208/runtimeerror-overlapped-overlapped-object-still-has-pending-operation-at-de.

Either fix the error, or do a workaround (e.g. check whether `congratulations` or `py310: OK`  appears at the end of the output.
RuntimeError on CI when running Tox on Windows, even if tests succeed
Sometimes the `tox` command fails on CI when run on Windows, e.g. see https://github.com/bancaditalia/black-it/actions/runs/6051431578/job/16422861344:

```
=== 87 passed, 19 skipped, 1 deselected, 218 warnings in 188.28s (0:03:08) ====
Traceback (most recent call last):
.pkg: _exit> python C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\site-packages\pyproject_api\_backend.py True poetry.core.masonry.api
  File "C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\site-packages\tox\session\cmd\run\single.py", line 105, in run_command_set
    current_outcome = tox_env.execute(
RuntimeError: <_overlapped.Overlapped object at 0x00000168A4752F70> still has pending operation at deallocation, the process may crash
  py310: OK (350.94=setup[159.83]+cmd[191.11] seconds)
  congratulations :) (353.58 seconds)
Error: Process completed with exit code 1.
```

Probably it is an `asyncio` issue inside `tox`, as shown here for a similar error: https://stackoverflow.com/questions/69833208/runtimeerror-overlapped-overlapped-object-still-has-pending-operation-at-de.

Either fix the error, or do a workaround (e.g. check whether `congratulations` or `py310: OK`  appears at the end of the output.


Discussion / hints:

Fix patch:
diff --git a/scripts/check-tox-output.ps1 b/scripts/check-tox-output.ps1
new file mode 100644
index 00000000..fa24191d
--- /dev/null
+++ b/scripts/check-tox-output.ps1
@@ -0,0 +1,29 @@
+# Check for arguments
+if (-not $args[0]) {
+    Write-Host "Please provide an argument for the environment, e.g. py38"
+    exit 1
+}
+# Read the content of $args[0]
+$output = Get-Content $args[0]
+
+# Get the last 10 lines of the output
+$last10Lines = $output[-10..-1]
+
+$testsSuccessful = $false
+
+# Check for success indicators in those lines
+foreach ($line in $last10Lines) {
+    if ($line -match "congratulations" -or $line -match "py\d+: OK") {
+        $testsSuccessful = $true
+        break
+    }
+}
+
+# Provide feedback on the success of tests
+if ($testsSuccessful) {
+    Write-Host "Tests were successful!"
+    exit 0 # Exit with a success code
+} else {
+    Write-Host "Tests failed or were inconclusive!"
+    exit 1 # Exit with a custom error code indicating test failure
+}


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 84961613..6092daf3 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -52,12 +52,14 @@ jobs:
       name: Unit tests and coverage (windows-latest)
       run: |
         $pyver = "${{ matrix.python-version }}" -replace '\.'
-        tox -e "py$pyver" -- -m 'not e2e'
+        tox -e "py$pyver" -- -m 'not e2e' | Tee-Object output.txt -ErrorAction SilentlyContinue
+        .\scripts\check-tox-output.ps1 output.txt
     - if: matrix.os == 'windows-latest'
       name: Notebook tests (windows-latest)
       run: |
         $pyver = "${{ matrix.python-version }}" -replace '\.'
-        tox -e "py$pyver-nb"
+        tox -e "py$pyver-nb" | Tee-Object output.txt -ErrorAction SilentlyContinue
+        .\scripts\check-tox-output.ps1 output.txt
     - name: Upload coverage to Codecov
       uses: codecov/codecov-action@v3
       with: