Skip to content

Commit b17a185

Browse files
metabiswadeepMolkreeterriko
authored
feat: Change LONG_TESTS() to give a boolean (#2411)
Co-authored-by: Dmitry Volodin <[email protected]> Co-authored-by: Terri Oda <[email protected]>
1 parent 8035752 commit b17a185

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

test/test_cli.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ class TestCLI(TempDirTest):
3232

3333
TEST_PATH = Path(__file__).parent.resolve()
3434

35-
@pytest.mark.skipif(LONG_TESTS() != 1, reason="No file downloads in short tests")
35+
@pytest.mark.skipif(not LONG_TESTS(), reason="No file downloads in short tests")
3636
def setup_method(self):
3737
shutil.copyfile(DEB_FILE_PATH, Path(self.tempdir) / "test.deb")
3838
download_file(CURL_7_20_0_URL, Path(self.tempdir) / CURL_7_20_0_RPM)
3939

40-
@pytest.mark.skipif(LONG_TESTS() != 1, reason="No file downloads in short tests")
40+
@pytest.mark.skipif(not LONG_TESTS(), reason="No file downloads in short tests")
4141
def test_extract_curl_7_20_0(self):
4242
"""Scanning curl-7.20.0"""
4343
assert main(["cve-bin-tool", "-l", "debug", "-x", self.tempdir]) != 0
4444

45-
@pytest.mark.skipif(LONG_TESTS() != 1, reason="No file downloads in short tests")
45+
@pytest.mark.skipif(not LONG_TESTS(), reason="No file downloads in short tests")
4646
def test_binary_curl_7_20_0(self):
4747
"""Extracting from rpm and scanning curl-7.20.0"""
4848
with Extractor() as ectx:
@@ -59,7 +59,7 @@ def test_binary_curl_7_20_0(self):
5959
!= 0
6060
)
6161

62-
@pytest.mark.skipif(LONG_TESTS() != 1, reason="No file downloads in short tests")
62+
@pytest.mark.skipif(not LONG_TESTS(), reason="No file downloads in short tests")
6363
def test_no_extraction(self):
6464
"""Test scanner against curl-7.20.0 rpm with extraction turned off"""
6565
assert main(["cve-bin-tool", str(Path(self.tempdir) / CURL_7_20_0_RPM)]) != 0
@@ -80,7 +80,7 @@ def test_extract_bad_zip_messages(self, caplog):
8080
main(["cve-bin-tool", bad_zip_file])
8181
assert "Failure extracting" in caplog.text
8282

83-
@pytest.mark.skipif(LONG_TESTS() != 1, reason="No file downloads in short tests")
83+
@pytest.mark.skipif(not LONG_TESTS(), reason="No file downloads in short tests")
8484
def test_exclude(self, caplog):
8585
"""Test that the exclude paths are not scanned"""
8686
test_path = Path(__file__).parent.resolve()
@@ -153,7 +153,7 @@ def test_invalid_parameter(self):
153153
main(["cve-bin-tool", self.tempdir, "--bad-param;cat hi"])
154154
assert e.value.args[0] == ERROR_CODES[SystemExit]
155155

156-
@pytest.mark.skipif(LONG_TESTS() != 1, reason="Update flag tests are long tests")
156+
@pytest.mark.skipif(not LONG_TESTS(), reason="Update flag tests are long tests")
157157
@pytest.mark.skipif(
158158
sys.platform == "win32", reason="Causing failures in CI on windows only"
159159
)
@@ -234,7 +234,7 @@ def test_runs(self, caplog):
234234
main(["cve-bin-tool", test_path, "-r", ",".join(runs)])
235235
self.check_checkers_log(caplog, skip_checkers, runs)
236236

237-
@pytest.mark.skipif(LONG_TESTS() != 1, reason="Update flag tests are long tests")
237+
@pytest.mark.skipif(not LONG_TESTS(), reason="Update flag tests are long tests")
238238
@pytest.mark.skipif(
239239
sys.platform == "win32", reason="Causing failures in CI on windows only"
240240
)
@@ -530,7 +530,7 @@ def test_SBOM(self, caplog):
530530
"There are 1 products with known CVEs detected",
531531
) in caplog.record_tuples
532532

533-
@pytest.mark.skipif(LONG_TESTS() != 1, reason="Skipping long tests")
533+
@pytest.mark.skipif(not LONG_TESTS(), reason="Skipping long tests")
534534
def test_console_output_depending_reportlab_existence(self, caplog):
535535
import subprocess
536536
from importlib.machinery import ModuleSpec

test/test_json.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import datetime
1010
import gzip
1111
import json
12-
import unittest
1312
from pathlib import Path
1413
from test.utils import LONG_TESTS
1514

@@ -30,7 +29,7 @@ class TestJSON:
3029
SCHEMA = requests.get(NVD_SCHEMA).json()
3130
LOGGER.info("Schema loaded successfully")
3231

33-
@unittest.skipUnless(LONG_TESTS() > 0, "Skipping long tests")
32+
@pytest.mark.skipif(not LONG_TESTS(), reason="Skipping long tests")
3433
@pytest.mark.parametrize(
3534
"year", list(range(2002, datetime.datetime.now().year + 1))
3635
)

test/test_scanner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def condensed_filepath(self, url, package_name):
241241
for d in list_data
242242
),
243243
)
244-
@unittest.skipUnless(LONG_TESTS() > 0, "Skipping long tests")
244+
@pytest.mark.skipif(not LONG_TESTS, reason="Skipping long tests")
245245
def test_version_in_package(self, url, package_name, product, version):
246246
"""Helper function to get a file (presumed to be a real copy
247247
of a library, probably from a Linux distribution) and run a
@@ -267,7 +267,7 @@ def test_version_in_package(self, url, package_name, product, version):
267267
The checker signature or url may be incorrect."""
268268
assert version in list_versions
269269

270-
@pytest.mark.skipif(LONG_TESTS() != 1, reason="Skipping long tests")
270+
@pytest.mark.skipif(not LONG_TESTS(), reason="Skipping long tests")
271271
@pytest.mark.skip(
272272
reason="Broken. See https://github.com/intel/cve-bin-tool/issues/2054"
273273
)

test/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def download_file(url, target):
5050
download.close()
5151

5252

53-
def LONG_TESTS():
54-
LONG_TESTS = 0
53+
def LONG_TESTS() -> bool:
5554
# override LONG_TESTS with environment variable if available
56-
if os.getenv("LONG_TESTS"):
57-
LONG_TESTS = int(os.getenv("LONG_TESTS"))
58-
return LONG_TESTS
55+
env_var = os.getenv("LONG_TESTS")
56+
if env_var:
57+
return bool(int(env_var))
58+
return False
5959

6060

6161
def EXTERNAL_SYSTEM() -> bool:

0 commit comments

Comments
 (0)