From 17e4af211041ca8cb161b337f78e9f967c2e5447 Mon Sep 17 00:00:00 2001 From: kasinadhsarma Date: Fri, 27 Dec 2024 09:48:32 +0530 Subject: [PATCH] Refactor linting test to capture pylint output and ensure stdout restoration on exceptions --- .../test_lint.cpython-310-pytest-8.3.4.pyc | Bin 1010 -> 1139 bytes tests/test_lint.py | 25 +++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/__pycache__/test_lint.cpython-310-pytest-8.3.4.pyc b/tests/__pycache__/test_lint.cpython-310-pytest-8.3.4.pyc index 4f8c6591f8c72b016287c6a951f818f804111470..c0de964314834bd5e6dfc8958d284af8390a6f60 100644 GIT binary patch delta 550 zcmYjN&1w`u5bo-p>6y%*LHs)iQNhC+2!dV=;z3Vd6kIT}9s;H|>#UQR*xe(n^stb4 z6%2D!VdoL_>MQsJ^9F(^^8!{+5bUBpzWToE?&|&%oQ7GIrV*pHcdMNJ;3wHtcz&|E zy<{kg=pdfNz>pyn$s|D!{SR!CB8=Hc{&Jh1jGzz4M&;$~@l)dBSzYcqGXZxc^H_rRn)O}Oy4Cxw!8y%k67YZ3FJF2I>7J?zr-4!>J-;3|I9G@>h$fAg2O-4E#t1X6^+dB!7<;**ddIR|x}j8WEy zuj;%od8yU;HWznZuan&KN~?Gvc{N7iOx>aE{s_d9du}2y2U~lw;~R@xYWUdgMxydwzS5iZ=)K8)lIT=fM!R}c@JkMHjc=iB+RtFiC9jKt`DXkeNQLYuV_~A1 ziawyF{XQ=Yw3W563wF)qX+Q-hg#wZmu_etSpn~SS0Cb-D8p{mQE>il$(0vi)SJoMN zsWAjfO;w@XOU(jq;Ret*SSB)#emB2|reR}zmcPSH_zBPV`I~2zcG8oRP|3u~S4A6Y zc}JWyO#PdFw8~w0gk*zgP$`}B$uLyING8kqhuAvu$u4;;OKUt;J*mpdcp45P)zXk~ fN`Ehtnr8n{*JsZ5Rg9Ccw*#c4L(pIjc;N9L-l$%) diff --git a/tests/test_lint.py b/tests/test_lint.py index 5c5cfab..d636eab 100644 --- a/tests/test_lint.py +++ b/tests/test_lint.py @@ -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