Skip to content

non-determinism in tests #534

@drammock

Description

@drammock

Locally if I run pytest -k test_play_sound I get all 4 tests passing, but if I just run pytest they seem to always fail. The error (see details) is a bit cryptic as it originates in portaudio C code, but the TLDR is that it can't initialize the ALSA stream, which causes the Python traceback:

RuntimeError: Could not set up sound card 'HDA Intel PCH: ALC892 Analog (hw:0,0)' (index=0) via ALSA, 2 channels @ 44100 Hz

(that card exists, and is specified as "SOUND_CARD_NAME": "HDA Intel PCH: ALC892 Analog" in my JSON config)

Details
expyfun/stimuli/tests/test_stimuli.py ..Expression 'ret' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1736
Expression 'AlsaOpen( &alsaApi->baseHostApiRep, params, streamDir, &self->pcm )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1904
Expression 'PaAlsaStreamComponent_Initialize( &self->playback, alsaApi, outParams, StreamDirection_Out, NULL != callback )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2175
Expression 'PaAlsaStream_Initialize( stream, alsaHostApi, inputParameters, outputParameters, sampleRate, framesPerBuffer, callback, streamFlags, userData )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2839
FExpression 'ret' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1736
Expression 'AlsaOpen( &alsaApi->baseHostApiRep, params, streamDir, &self->pcm )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1904
Expression 'PaAlsaStreamComponent_Initialize( &self->playback, alsaApi, outParams, StreamDirection_Out, NULL != callback )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2175
Expression 'PaAlsaStream_Initialize( stream, alsaHostApi, inputParameters, outputParameters, sampleRate, framesPerBuffer, callback, streamFlags, userData )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2839
FExpression 'ret' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1736
Expression 'AlsaOpen( &alsaApi->baseHostApiRep, params, streamDir, &self->pcm )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1904
python3.13: src/hostapi/alsa/pa_linux_alsa.c:2178: PaAlsaStream_Initialize: Assertion `self->capture.nfds || self->playback.nfds' failed.
Fatal Python error: Aborted

I thought this was due to a recent OS change where I uninstalled portaudio in favor of using pipewire everywhere (to fix some issues I was having with my speakers and mic), but then I realized the tests pass when run in isolation, so I don't think that can be the cause. FWIW, installing portaudio into the mamba environment don't seem to help.

Relatedly, when run in isolation pytest -k test_ec[pyglet] and pytest -k test_ec[sounddevice] and pytest -k test_gapless[sounddevice] all pass, but all the EC tests fail if run as pytest -k test_ec and all three fail if run as just pytest. They give different python tracebacks, e.g.:

  • pyglet.media.drivers.pulse.interface.PulseAudioException: PulseAudioException: [8] Timeout
  • sounddevice.PortAudioError: Error opening OutputStream: Device unavailable [PaErrorCode -9985]

...but the same C lib traceback also appears, so I think it's all the same underlying cause.

A hunch is that there's some sort of concurrency lock or teardown happening in the audio libs, causing the ALSA stream initialization to fail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions