未找到 ALSA - github 动作单元测试,正确设置 env/envvars

ALSA not found - github actions unit testing, setting env/envvars correctly

我的 .github/workflows 文件夹中有以下 yaml。

name: Run Python Tests
on:
  push:
    branches:
      - main

  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["2.7", "3.6", "3.7", "3.8", "3.9"]
    steps:
      - uses: actions/checkout@v3
      - name: Install Python ${{ matrix.python-version }}
        uses: actions/setup-python@v3
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      - name: Run tests with unittest 
        run: python -m unittest test.py 

当我创建 PR 时,它运行测试...但是它们在 github 而不是在我的本地机器上失败。

错误如下:

0s
Run python -m unittest test.py
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5220:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5220:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/unittest/__main__.py", line 18, in <module>
    main(module=None)
  File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/unittest/main.py", line 100, in __init__
    self.parseArgs(argv)
  File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/unittest/main.py", line 147, in parseArgs
    self.createTests()
  File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/unittest/main.py", line 158, in createTests
    self.test = self.testLoader.loadTestsFromNames(self.testNames,
  File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/unittest/loader.py", line 220, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/unittest/loader.py", line 220, in <listcomp>
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/unittest/loader.py", line 154, in loadTestsFromName
    module = __import__(module_name)
  File "/home/runner/work/2dshooter/2dshooter/test.py", line 5, in <module>
    from test_func import *
  File "/home/runner/work/2dshooter/2dshooter/test/test_func.py", line 2, in <module>
    from func import *
  File "/home/runner/work/2dshooter/2dshooter/func.py", line 6, in <module>
    from values import *
  File "/home/runner/work/2dshooter/2dshooter/values.py", line 10, in <module>
    pygame.mixer.init()
pygame.error: ALSA: Couldn't open audio device: No such file or directory
pygame 2.1.2 (SDL 2.0.16, Python 3.8.12)
Hello from the pygame community. https://www.pygame.org/contribute.html
VALUE INIT
Error: Process completed with exit code 1.

仔细阅读 - 看起来罪魁祸首是当我们

时实际上并不存在的音频驱动程序
    runs-on: ubuntu-latest

不包括音频驱动程序?

我已经尝试将以下内容添加到 yaml 文件中(直接在运行时下方)


    env:
      SDL_AUDIODRIVER: 'ALSA'

这也不起作用 - 并产生相同的错误。

那么如何让 GitHub 中的容器拥有正确的音频驱动程序?

A github actions 计算机没有任何扬声器可以输出音频,也没有显示器可以输出视频。这是一个无头系统。

解决方法是设置

    env:
      SDL_VIDEODRIVER: "dummy"
      SDL_AUDIODRIVER: "disk"

https://github.com/pygame/pygame/issues/2985