Skip to content

Commit

Permalink
Use unittest.mock.patch.dict to set envvar
Browse files Browse the repository at this point in the history
  • Loading branch information
JokeWaumans committed Nov 18, 2024
1 parent 62bf2dc commit 70ab119
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions tests/test_coverity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from io import StringIO
from pathlib import Path
from unittest import TestCase
from unittest import TestCase, mock
from unittest.mock import patch

from mlx.warnings import WarningsPlugin, warnings_wrapper
Expand All @@ -19,19 +19,12 @@ def ordered(obj):
else:
return obj


@mock.patch.dict(os.environ, {"MIN_COV_WARNINGS": "1", "MAX_COV_WARNINGS": "2"})
class TestCoverityWarnings(TestCase):
def setUp(self):
os.environ["MIN_COV_WARNINGS"] = "1"
os.environ["MAX_COV_WARNINGS"] = "2"
self.warnings = WarningsPlugin(verbose=True)
self.warnings.activate_checker_name('coverity')

def tearDown(self):
for var in ('MIN_POLY_WARNINGS', 'MAX_POLY_WARNINGS'):
if var in os.environ:
del os.environ[var]

def test_no_warning_normal_text(self):
dut = 'This should not be treated as warning'
self.warnings.check(dut)
Expand Down Expand Up @@ -79,9 +72,9 @@ def test_code_quality_without_config(self):
str(TEST_IN_DIR / 'defects.txt'),
])
self.assertEqual(8, retval)
with open(out_file) as file:
with open(out_file) as file:
cq_out = json.load(file)
with open(ref_file) as file:
with open(ref_file) as file:
cq_ref = json.load(file)
self.assertEqual(ordered(cq_out), ordered(cq_ref))

Expand All @@ -95,8 +88,8 @@ def test_code_quality_with_config(self):
str(TEST_IN_DIR / 'defects.txt'),
])
self.assertEqual(3, retval)
with open(out_file) as file:
with open(out_file) as file:
cq_out = json.load(file)
with open(ref_file) as file:
with open(ref_file) as file:
cq_ref = json.load(file)
self.assertEqual(ordered(cq_out), ordered(cq_ref))

0 comments on commit 70ab119

Please sign in to comment.