Skip to content

Commit

Permalink
Show pytest/ruff errors in actions output system
Browse files Browse the repository at this point in the history
The GitHub Actions CI/CD can show errors in pull request per line. This
is much better than reading stdout/stderr outputs. This patch adds a
pytest plugin that can generate gh actions reports, and opts Ruff into
github actions output when ran on CI.
  • Loading branch information
ikalnytskyi committed May 7, 2024
1 parent efb22c3 commit 70dc8bf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:

- name: Run ruff
run: pipx run tox -e lint
env:
RUFF_OUTPUT_FORMAT: github

test:
strategy:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ optional = true
[tool.poetry.group.test.dependencies]
pytest = "^7.1"
responses = "^0.20"
pytest-github-actions-annotate-failures = "*"

[tool.poetry.plugins."httpie.plugins.auth.v1"]
credential-store = "httpie_credential_store:CredentialStoreAuthPlugin"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_keychain_password_store.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Tests password-store keychain provider."""

import pathlib
import re
import shutil
import subprocess
import pathlib
import sys
import tempfile
import textwrap
Expand All @@ -16,7 +16,7 @@

pytestmark = pytest.mark.skipif(
not shutil.which("pass"),
reason="password-store is not found",
reason="password-store is not found"
)


Expand Down Expand Up @@ -101,7 +101,7 @@ def test_secret_retrieved(testkeychain, gpg_key_id):
subprocess.run("pass generate testservice/testuser 14", shell=True, check=False)

secret = testkeychain.get(name="testservice/testuser")
assert len(secret) == 14
assert len(secret) == 12

Check failure on line 104 in tests/test_keychain_password_store.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.8)

test_secret_retrieved AssertionError: assert 14 == 12 + where 14 = len('g?<2c|,Rix.B{*')

Check failure on line 104 in tests/test_keychain_password_store.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.9)

test_secret_retrieved AssertionError: assert 14 == 12 + where 14 = len('IrG.gstwce6u4_')

Check failure on line 104 in tests/test_keychain_password_store.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.10)

test_secret_retrieved AssertionError: assert 14 == 12 + where 14 = len('azv}AF7RPI[Q#y')

Check failure on line 104 in tests/test_keychain_password_store.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.11)

test_secret_retrieved assert 14 == 12 + where 14 = len("maBtUO=.Q$Qv'}")

Check failure on line 104 in tests/test_keychain_password_store.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.12)

test_secret_retrieved assert 14 == 12 + where 14 = len('"]`9k:X^!2D4sM')

Check failure on line 104 in tests/test_keychain_password_store.py

View workflow job for this annotation

GitHub Actions / test (macos-latest, 3.12)

test_secret_retrieved AssertionError: assert 14 == 12 + where 14 = len(':/|qFQ=l|ZG6uo')


def test_secret_not_found(testkeychain):
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ skip_install = true
[testenv:test]
commands_pre = poetry install --with test
commands = poetry run pytest -vv {posargs:.}
passenv = GITHUB_ACTIONS

[testenv:lint]
commands_pre = poetry install --only lint
commands =
ruff check {posargs:.}
ruff format --check --diff {posargs:.}
passenv = RUFF_OUTPUT_FORMAT

0 comments on commit 70dc8bf

Please sign in to comment.