-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor linting test to capture pylint output and ensure stdout rest…
…oration on exceptions
- Loading branch information
1 parent
3e377c3
commit 17e4af2
Showing
2 changed files
with
21 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |