Workflow using docker-compose running pytest results I/O operation on closed file

I’m trying to setup workflow for project, which uses docker-compose to run tests with pytest. However executing pytest results the following error on GitHub Actions. This works locally fine.

GitHub Actions log on failure:

Test with pytest1s
##[error]Process completed with exit code 255.
Run docker-compose exec app pytest
[3233] Failed to execute script docker-compose
Traceback (most recent call last):
  File "site-packages/dockerpty/pty.py", line 334, in start
  File "site-packages/dockerpty/pty.py", line 367, in _hijack_tty
  File "site-packages/dockerpty/io.py", line 59, in select
  File "site-packages/dockerpty/io.py", line 351, in fileno
  File "site-packages/dockerpty/io.py", line 103, in fileno
  File "socket.py", line 638, in fileno
ValueError: I/O operation on closed file.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bin/docker-compose", line 6, in <module>
  File "compose/cli/main.py", line 72, in main
  File "compose/cli/main.py", line 128, in perform_command
  File "compose/cli/main.py", line 519, in exec_command
  File "site-packages/dockerpty/pty.py", line 338, in start
  File "site-packages/dockerpty/io.py", line 32, in set_blocking
  File "site-packages/dockerpty/io.py", line 351, in fileno
  File "site-packages/dockerpty/io.py", line 103, in fileno
  File "socket.py", line 638, in fileno
ValueError: I/O operation on closed file.
##[error]Process completed with exit code 255.

Dockerfile

FROM python:3.7

WORKDIR /src

RUN pip install --upgrade pip
# Install unit test dependencies
RUN pip install pytest pytest-cov

docker-compose.yaml

version: '3'
services:
  app:
    build: .
    container_name: app
    volumes:
    - ./:/src
    stdin_open: true
    tty: true
    entrypoint: /bin/bash
    environment:
      - PYTHONPATH=./src

actions.yaml

on:
  push:
    branches: [master]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: docker-compose up
      env:
        COMPOSE_INTERACTIVE_NO_CLI: 1
      run: docker-compose up -d
    - name: Check running containers
      run: docker-compose ps -a
    - name: Check logs
      run: docker-compose logs app
    - name: Test with pytest
      env:
        COMPOSE_INTERACTIVE_NO_CLI: 1
      run: docker-compose exec app pytest

I put up an example repo, check it out here:

https://github.com/villekr/github-actions-dockercompose-pytest

@villekr ,

I have opened an issue ticket (see actions/virtual-environments#808) to help you report this problem to the appropriate engineering team for further investigation and evaluation.

You can follow that issue ticket and add you comments here.

1 Like

@villekr ,

I forked your repository and tested with the solution mentioned by  @Darleev in the issue ticket, it works fine and the problem solved.

The solution is changing the command for pytest as below, adding the option ’ -T’:

docker-compose exec -T app pytest

See here: https://github.com/ForksForTest/github-actions-dockercompose-pytest/actions/runs/92858972/workflow

Please try it on your side.