Skip to content

Commit

Permalink
Force SDL_VIDEODRIVER=dummy for tests
Browse files Browse the repository at this point in the history
Background: my tests rely on pygame.key.name(K_RCTRL) returning
something meaningful (like "right ctrl").  This function is a thin
wrapper around SDL_GetKeyName(), which looks up a key from a lookup
table.  That lookup table is not static for some reason in SDL 1.2,
and gets initialized by this call chain:

  SDL_KeyboardInit() called by
  SDL_StartEventLoop() called by
  SDL_VideoInit() called by
  SDL_InitSubSystem() called by
  PyGame_Video_AutoInit() called by
  pygame.init() called by
  pygame.tests.test_ui.setUp()

Now SDL_VideoInit() also initializes other things, like the SDL video
subsystem, for which it tries various backends (including X11, aalib and
caca).  This explains why the presence/absence/values of various
environment variables (DISPLAY/TERM) could make or break the tests, or
why it would suddenly and unexpectedly flash and clear the screen for
tox -e coverage.

By forcing a specific SDL video driver (dummy) we remove non-determinism
and hopefully the issue can rest.
  • Loading branch information
mgedmin committed Sep 22, 2016
1 parent d9fa607 commit e8f599d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ install:
- pip install -U pip
- pip install coverage coveralls -e .
script:
- xvfb-run -a coverage run --source=src/pyspacewar test.py
- coverage run --source=src/pyspacewar test.py
after_success:
- coveralls
notifications:
Expand Down
3 changes: 1 addition & 2 deletions src/pyspacewar/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,8 @@ def doctest_FrameRateCounter_fps():

def setUp(test=None):
import pygame
os.environ['SDL_VIDEODRIVER'] = 'dummy'
pygame.init() # so that pygame.key.name() works
# unfortunately, on linux, if $DISPLAY is unset, pygame.init doesn't
# complain, but pygame.key.name() returns 'unknown key' for all keys


def test_suite():
Expand Down
5 changes: 0 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ envlist =
install_command = python -m pip install -U {opts} {packages}
deps =
pip
# if DISPLAY is unset on Linux, pygame returns 'unknown key' for all keys
# which makes tests fail :/
passenv =
DISPLAY
TERM
commands =
python test.py

Expand Down

0 comments on commit e8f599d

Please sign in to comment.