Skip to content

Fix and improve tests#686

Merged
tobixen merged 3 commits into
python-caldav:masterfrom
betaboon:fix-and-improve-tests
Jun 15, 2026
Merged

Fix and improve tests#686
tobixen merged 3 commits into
python-caldav:masterfrom
betaboon:fix-and-improve-tests

Conversation

@betaboon

@betaboon betaboon commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

hi there.

i ran into your repository while trying to fix some builds for nixpkgs on macos.
i ran into three problems:

  • the tests were rather slow (felt like taking forever)
  • some tests were failing
  • some tests were only failing in nix build sandbox

i hope this changes are welcome.

speed improvements

last successful job in this repo: https://github.com/python-caldav/caldav/actions/runs/27359451891/job/80842588388

[7](https://github.com/python-caldav/caldav/actions/runs/27359451891/job/80842588388#step:14:78)
========== 1394 passed, 169 skipped, 1 xpassed in 2165.85s (0:36:05) ===========
.pkg: _exit> python /opt/hostedtoolcache/Python/3.14.5/x64/lib/python3.14/site-packages/pyproject_api/_backend.py True hatchling.build
  py: OK (2195.64=setup[26.22]+cmd[2169.42] seconds)
  congratulations :) (2195.67 seconds)

with this branch locally:

================ 808 passed, 61 skipped, 1 xpassed in 167.14s (0:02:47) ================
.pkg: _exit> python /Users/betaboon/src/python/caldav/.venv/lib/python3.14/site-packages/pyproject_api/_backend.py True hatchling.build
  py: OK (168.95=setup[1.34]+cmd[167.61] seconds)
  congratulations :) (168.96 seconds)

@tobixen

tobixen commented Jun 14, 2026

Copy link
Copy Markdown
Member

Thanks, I will look through it.

Comment thread caldav/testing.py
betaboon and others added 3 commits June 15, 2026 07:18
XandikosServer.stop() scheduled a coroutine via run_coroutine_threadsafe
that awaited the aiohttp runner cleanup and then called loop.stop() from
*inside* that same coroutine.  Stopping the loop from within the coroutine
prevents the loop from delivering the coroutine's result back to the
concurrent.futures.Future, so .result(timeout=10) never resolved and blocked
for the full 10 seconds.

Because the embedded server is started and stopped once per test, this added
~10s to every Xandikos test teardown, making the integration suite take many
minutes and appear to hang.  Measured stop() dropped from 10.018s to 0.009s.

Fix: await only the runner cleanup inside the coroutine, then stop the loop
from outside it via call_soon_threadsafe.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The test_server fixture in AsyncFunctionalTestsBaseClass was scope="class"
but defined as a plain instance method.  Recent pytest raises
PytestRemovedIn10Warning for that pattern, and the project's
filterwarnings = ["error"] turns it into a hard error -- erroring out all
122 async integration tests at fixture setup.

The fixture only reads the class-level `server` attribute and starts/stops it,
so there is no per-instance state to lose.  Make it a @classmethod as the
warning recommends.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
read_config only caught FileNotFoundError when probing the optional config
file locations.  When HOME is unset (e.g. a Nix build sandbox), the default
path expands to '//.config//caldav/calendar.conf', which open() rejects with
IsADirectoryError.  That OSError propagated out of an optional-config probe,
breaking get_davclient() and even crashing pytest's terminal summary renderer.

Catch OSError (covers not-found, is-a-directory, and permission errors) and
treat any of them as 'no config here', returning {} as before.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@betaboon betaboon force-pushed the fix-and-improve-tests branch from fe38acf to 4caf646 Compare June 15, 2026 05:18
@tobixen tobixen merged commit 6bbad0a into python-caldav:master Jun 15, 2026
10 checks passed
@tobixen

tobixen commented Jun 15, 2026

Copy link
Copy Markdown
Member

There will be a new release of the caldav library soon ... though, I cannot promise how soon (I have a ton of commits done by Claude, I need to go through and review all of them manually, fix up changelog and commit messages, run all the tests, write some release notes ... and the rest of the month I'm super-busy with other things).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants