What to do when no display name occurs when unittesting Python + Tkinter on Github Actions Memo

Display settings are required when unittesting Python + Tkinter on Github Actions

After git pushing the code repository developed in Python, unittest is automatically run on Github Actions.

When testing a module that requires screen drawing such as Tkinter on GitActions, it is necessary to set the display in the virtual environment. If this setting is not made, an error will be spit out as no display name.

The following is a memo of how to deal with the error. Before running the unit test, set the display with the following contents.

.github\workflows\test.yml


disp=:99
screen=0
geom=640x480x24
exec Xvfb $disp -screen $screen $geom 2>/tmp/Xvfb.log &
export DISPLAY=:99

The yml file for Github Actions looks like this. It is a rule to keep the yml file in .github \ workflows.

.github\workflows\test.yml


name: Python package

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [3.7]

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    #Installation
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install flake8 pytest
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    #View python version
    - name: Display Python version
      run: python -c "import sys; print(sys.version)"
    #Run unittest
    - name: Test
      run: |
        disp=:99
        screen=0
        geom=640x480x24
        exec Xvfb $disp -screen $screen $geom 2>/tmp/Xvfb.log &
        export DISPLAY=:99
        python -m unittest discover tests

Reference material

I referred to this article on StackOverflow. _tkinter.TclError: no display name and no $DISPLAY environment variable

Other tips on Github Actions

If you want to skip unittests in Github Actions

test.py


@unittest.skipIf("GITHUB_ACTIONS" in os.environ and os.environ["GITHUB_ACTIONS"] == "true", "Skipping this test on Github Actions")
class TestHoge(unittest.TestCase):
    def setUp(self):
        print("setUp")

    def test_hoge(self):
        print("test_hoge")

Recommended Posts

What to do when no display name occurs when unittesting Python + Tkinter on Github Actions Memo
What to do when ModuleNotFoundError: No module named'XXX' occurs in Python
What to do when "cannot import name xxx" [Python]
What to do when PermissionError of tempfile.mkstemp occurs
What to do if CERTIFICATE_VERIFY_FAILED occurs when nltk.download () is done on macOS pyhon
[python] What to do when an error occurs in send_keys of headless chrome
What to do when [Errno 2] No such file or directory appears in Python
What to do when you can't bind CaboCha to Python
[Python] Type Error:'WebElement' object is not iterable What to do when an error occurs
What to do if "export" keeps appearing on terminal when trying to put Python on macOS
What to do when python3 type venv does not work well on Raspberry Pi
[Python] What to do when No module named'pyproj.datadir' appears when Exe is done with PyInstaller
What to do when Japanese is not displayed on matplotlib
What to do when you get an error saying "Name resolution temporarily failed" on linux
What to do when a Remove Error occurs when updating conda
What to do when there is no response due to Proxy setting in Python web scraping
What to do when an error occurs with import _ssl
What to do when "SSL: CERTIFICATE_VERIFY_FAILED _ssl.c: 1056" appears in Python
ImportError: No module What to do when you are told
What to do if Python doesn't work on Git for Windows
[Beanstalk] What to do when an error occurs with import uuid
What to do if Insecure Platform Warning appears when running Python
What to do if PyAudio cannot be installed on Python 3.7, 3.8, 3.9 on Windows
What to do when the value type is ambiguous in Python?
What to do when Ubuntu crashes
What to do with PYTHON release?
What to do if you get a Permission denied (public key) error when trying to pull on Github
[Python] What to do when an error related to SSL authentication is returned
What to do if an error occurs when importing numpy with VScode
Notes on what to do when matplotlib scatter () / scatter3d () does not work
[OSX] [pyenv] What to do when an SSL error occurs in pip
What I referred to when studying tkinter
What to do if an error occurs when loading a python project created with poetry into VS Code
What to do when SSL error occurs in pip in Windows10, miniconda, VScode environment
What to do when a warning appears around Python integration in Neovim's CheckHealth
What to do if a Unicode Encode Error occurs in Sublime Text Python
What to do if you get an error when installing python with pyenv
What to do if an SSL connection error (ssl.SSLError: [SSL: DH_KEY_TOO_SMALL]) occurs on Ubuntu 20.04
[Python] What I did to do Unit Test
What to do to get google spreadsheet in python
What to do if "amazon-linux-extras" → "No module named amazon_linux_extras"
What to do if you get an OpenSSL error when installing Python 2 with pyenv
What to do if the Microsoft Store opens even if you run python on Windows
What to do if you get `No kernel for language python found` in Hydrogen
What to do if you get an error when importing matplotlib in Python (Mac)
What to do if Python IntelliSense is not displayed in VS Code on Windows
What to do when Python starts up in Anaconda does not come out unexpectedly
[Introduction to Python] What is the important "if __name__ =='__main__':" when dealing with modules?
What to do when "Type Error: must be _socket.socket, not socket" appears on GAE
What to do if you get the error ʻERR_FEATURE_UNAVAILABLE_ON_PLATFORM` when using ts-node-dev on Linux