我的 .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 中的容器擁有正確的音頻驅動程式?
uj5u.com熱心網友回復:
github 操作計算機沒有任何揚聲器可以輸出音頻,也沒有顯示幕可以輸出視頻。這是一個無頭系統。
解決方案是設定
env:
SDL_VIDEODRIVER: "dummy"
SDL_AUDIODRIVER: "disk"
見https://github.com/pygame/pygame/issues/2985
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/478944.html
標籤:Python 单元测试 github 游戏 github-动作
上一篇:使用嵌套函式更改進行模擬測驗
下一篇:curlPOST上傳檔案測驗
