Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show ruff version on test start #289

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
)
Comment on lines +34 to +40
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use this instead of simply executable.version so we can get richer information when available.


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