Skip to content

Commit

Permalink
Show ruff version on test start (#289)
Browse files Browse the repository at this point in the history
Uses the long ruff version if supported by the binary.

Useful for testing e.g. #286
and astral-sh/ruff#8016

```
❯ pytest
======================================================================================================================================================= test session starts ========================================================================================================================================================
platform darwin -- Python 3.7.17, pytest-7.4.2, pluggy-1.2.0
ruff-version: 0.1.1+15 (860ffb954 2023-10-20)
rootdir: /Users/mz/eng/src/astral-sh/ruff-lsp
configfile: pyproject.toml
plugins: typeguard-3.0.2, asyncio-0.21.1, anyio-3.7.1
asyncio: mode=strict
collected 3 items                                                                                                                                                                                                                                                                                                                  

tests/test_format.py .                                                                                                                                                                                                                                                                                                       [ 33%]
tests/test_server.py ..                                                                                                                                                                                                                                                                                                      [100%]

======================================================================================================================================================== 3 passed in 0.68s =========================================================================================================================================================
```
  • Loading branch information
zanieb authored Oct 23, 2023
1 parent 0bb19b4 commit 88c7379
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import subprocess
from pathlib import Path

import pytest
from packaging.version import Version

from ruff_lsp.server import _find_ruff_binary, _get_global_defaults, uris
from ruff_lsp.server import Executable, _find_ruff_binary, _get_global_defaults, uris
from ruff_lsp.settings import WorkspaceSettings


@pytest.fixture(scope="session")
def ruff_version() -> Version:
def _get_ruff_executable() -> Executable:
# Use the ruff-lsp directory as the workspace
workspace_path = str(Path(__file__).parent.parent)

Expand All @@ -19,4 +19,25 @@ def ruff_version() -> Version:
workspace=uris.from_fs_path(workspace_path),
)

return _find_ruff_binary(settings, version_requirement=None).version
return _find_ruff_binary(settings, version_requirement=None)


@pytest.fixture(scope="session")
def ruff_version() -> Version:
return _get_ruff_executable().version


def pytest_report_header(config):
"""Add ruff version to pytest header."""
executable = _get_ruff_executable()

# Display the long version if the executable supports it
try:
output = subprocess.check_output([executable.path, "version"]).decode().strip()
except subprocess.CalledProcessError:
output = (
subprocess.check_output([executable.path, "--version"]).decode().strip()
)

version = output.replace("ruff ", "")
return [f"ruff-version: {version}"]

0 comments on commit 88c7379

Please sign in to comment.