Skip to content

Commit

Permalink
Refactor linting test to capture pylint output and ensure stdout rest…
Browse files Browse the repository at this point in the history
…oration on exceptions
  • Loading branch information
kasinadhsarma committed Dec 27, 2024
1 parent 3e377c3 commit 17e4af2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Binary file modified tests/__pycache__/test_lint.cpython-310-pytest-8.3.4.pyc
Binary file not shown.
25 changes: 21 additions & 4 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import os
import pytest
import sys
from io import StringIO
from pylint.lint import Run
import pytest

def test_pylint():
"""Run pylint on the project."""
results = Run(['models'], do_exit=False)
score = results.linter.stats.global_note
assert score >= 7.0, f"Code quality score {score} is below threshold"
# Redirect stdout to capture pylint's output
old_stdout = sys.stdout
sys.stdout = StringIO()

try:
# Run pylint with exit=False
results = Run(['models'], exit=False)
score = results.linter.stats.global_note

# Restore stdout
sys.stdout = old_stdout

# Check the code quality score
assert score >= 7.0, f"Code quality score {score} is below threshold"
except:
# Restore stdout before raising any exception
sys.stdout = old_stdout
raise

0 comments on commit 17e4af2

Please sign in to comment.