Skip to content

Commit caaafa4

Browse files
authored
smoketests: Allow to skip tests requiring dotnet (#1726)
1 parent 336056e commit caaafa4

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

smoketests/__init__.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131

3232
# this is set to true when the --docker flag is passed to the cli
3333
HAVE_DOCKER = False
34+
# this is set to true when the --skip-dotnet flag is not passed to the cli,
35+
# and a dotnet installation is detected
36+
HAVE_DOTNET = False
3437

3538
# we need to late-bind the output stream to allow unittests to capture stdout/stderr.
3639
class CapturableHandler(logging.StreamHandler):
@@ -138,21 +141,6 @@ def run_cmd(*args, capture_stderr=True, check=True, full_output=False, cmd_name=
138141
def spacetime(*args, **kwargs):
139142
return run_cmd(SPACETIME_BIN, *args, cmd_name="spacetime", **kwargs)
140143

141-
142-
def _check_for_dotnet() -> bool:
143-
try:
144-
version = run_cmd("dotnet", "--version", log=False).strip()
145-
if int(version.split(".")[0]) < 8:
146-
logging.info(f"dotnet version {version} not high enough (< 8.0), skipping dotnet smoketests")
147-
return False
148-
except Exception as e:
149-
raise e
150-
return False
151-
return True
152-
153-
HAVE_DOTNET = _check_for_dotnet()
154-
155-
156144
class Smoketest(unittest.TestCase):
157145
MODULE_CODE = TEMPLATE_LIB_RS
158146
AUTOPUBLISH = True

smoketests/__main__.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
import subprocess
44
import unittest
55
import argparse
6-
from tempfile import TemporaryDirectory
7-
from pathlib import Path
86
import os
97
import re
108
import fnmatch
119
import json
12-
from . import TEST_DIR, STDB_DIR, STDB_CONFIG, build_template_target
10+
from . import TEST_DIR, build_template_target
1311
import smoketests
1412
import logging
1513

@@ -23,6 +21,16 @@ def check_docker():
2321
print("Docker container not found, is SpacetimeDB running?")
2422
exit(1)
2523

24+
def check_dotnet() -> bool:
25+
try:
26+
version = smoketests.run_cmd("dotnet", "--version", log=False).strip()
27+
if int(version.split(".")[0]) < 8:
28+
logging.info(f"dotnet version {version} not high enough (< 8.0), skipping dotnet smoketests")
29+
return False
30+
except Exception:
31+
return False
32+
return True
33+
2634
class ExclusionaryTestLoader(unittest.TestLoader):
2735
def __init__(self, excludelist=()):
2836
super().__init__()
@@ -49,6 +57,7 @@ def main():
4957
parser = argparse.ArgumentParser()
5058
parser.add_argument("test", nargs="*", default=tests)
5159
parser.add_argument("--docker", action="store_true")
60+
parser.add_argument("--skip-dotnet", action="store_true", help="ignore tests which require dotnet")
5261
parser.add_argument("--show-all-output", action="store_true", help="show all stdout/stderr from the tests as they're running")
5362
parser.add_argument("--parallel", action="store_true", help="run test classes in parallel")
5463
parser.add_argument("-j", dest='jobs', help="Set number of jobs for parallel test runs. Default is `nproc`", type=int, default=0)
@@ -71,6 +80,12 @@ def main():
7180
subprocess.Popen(["docker", "logs", "-f", docker_container])
7281
smoketests.HAVE_DOCKER = True
7382

83+
if not args.skip_dotnet:
84+
smoketests.HAVE_DOTNET = check_dotnet()
85+
if not smoketests.HAVE_DOTNET:
86+
print("no suitable dotnet installation found")
87+
exit(1)
88+
7489
add_prefix = lambda testlist: [TESTPREFIX + test for test in testlist]
7590
import fnmatch
7691
excludelist = add_prefix(args.exclude)

0 commit comments

Comments
 (0)