-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DM-11514: Use pytest as simple test runner #34
Changes from all commits
2c6b210
315568c
2f45aaa
0fefba4
0701af8
365ef76
d16253c
42618a0
2832d91
b083808
9a44a87
5ba5ce9
8b18099
f4d0e2f
0759c19
5d01e4d
032ddf4
3bf8412
f7b7d39
88ce337
415bdd6
68ad088
e48effd
f5d07ad
cb92d30
b85720c
185a25c
44d74d5
e2044be
e544b15
857b5d9
d1d7c23
a4e6ccb
e37d2fa
1990145
e000e06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.cache | ||
.sconsign.dblite | ||
config.log | ||
.sconf_temp | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,7 +117,7 @@ def SourcesForSharedLibrary(self, files): | |
obj = self.SharedObject(ccFile) | ||
objs.append(obj) | ||
|
||
objs = sorted(state.env.Flatten(sources), key=str) | ||
objs = sorted(state.env.Flatten(objs), key=str) | ||
return objs | ||
|
||
|
||
|
@@ -155,7 +155,7 @@ def filesToTag(root=None, fileRegex=None, ignoreDirs=None): | |
# | ||
# Remove files generated by swig | ||
# | ||
for swigFile in [f for f in filenames if re.search(r"\.i$", f)]: | ||
for swigFile in [f for f in filenames if f.endswith(".i")]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry to see we still need this, but presumably removing SWIG support should be done on a different ticket. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The svn support can almost certainly be removed as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in this ticket. |
||
name = os.path.splitext(swigFile)[0] | ||
candidates = [f for f in candidates if not re.search(r"%s(_wrap\.cc?|\.py)$" % name, f)] | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -587,4 +587,4 @@ def getLibs(env, categories="main"): | |
|
||
SConsEnvironment.getLibs = getLibs | ||
|
||
## @} | ||
## @} # noqa E266 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,7 +195,16 @@ def finish(defaultTargets=DEFAULT_TARGETS, | |
nfail=`find {0} -name \*.failed | wc -l | sed -e 's/ //g'`; \ | ||
if [ $$nfail -gt 0 ]; then \ | ||
echo "Failed test output:" >&2; \ | ||
find {0} -name \*.failed -exec cat {{}} \; >&2; \ | ||
for f in `find {0} -name \*.failed`; do \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are the newline escapes needed inside of a heredoc? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean the bit after the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No -- I meant why do any of the lines need escapes?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No idea. Haven't checked. I was using the style from the pre-existing code. They all do turn up on a single line when you print the debug so I'm not sure why @RobertLuptonTheGood did it like that originally. |
||
case "$$f" in \ | ||
*.xml.failed) \ | ||
echo "Global pytest output is in $$f" >&2; \ | ||
;; \ | ||
*.failed) \ | ||
cat $$f >&2; \ | ||
;; \ | ||
esac; \ | ||
done; \ | ||
echo "The following tests failed:" >&2;\ | ||
find {0} -name \*.failed >&2; \ | ||
echo "$$nfail tests failed" >&2; exit 1; \ | ||
|
@@ -299,8 +308,10 @@ def rewrite_shebang(target, source, env): | |
if src is None: | ||
src = Glob("#bin.src/*") | ||
for s in src: | ||
if str(s) != "SConscript": | ||
result = state.env.Command(target=os.path.join(Dir("#bin").abspath, str(s)), | ||
filename = str(s) | ||
# Do not try to rewrite files starting with non-letters | ||
if filename != "SConscript" and re.match("[A-Za-z]", filename): | ||
result = state.env.Command(target=os.path.join(Dir("#bin").abspath, filename), | ||
source=s, action=rewrite_shebang) | ||
state.targets["shebang"].extend(result) | ||
|
||
|
@@ -424,6 +435,13 @@ def doc(config="doxygen.conf.in", projectName=None, projectNumber=None, **kw): | |
# @param pyList A sequence of Python tests to run (including .py extensions). | ||
# Defaults to a *.py glob of the tests directory, minus any | ||
# files corresponding to the SWIG modules in swigFileList. | ||
# An empty list will enable automated test discovery. | ||
# @param pySingles A sequence of Python tests to run (including .py extensions) | ||
# as independent single tests. By default this list is empty | ||
# and all tests are run in a single pytest call. | ||
# Items specified here will not appear in the default pyList | ||
# and should not start with "test_" (such that they will not | ||
# be auto-discoverable by pytest). | ||
# @param ccList A sequence of C++ unit tests to run (including .cc extensions). | ||
# Defaults to a *.cc glob of the tests directory, minus any | ||
# files that end with *_wrap.cc and files present in swigSrc. | ||
|
@@ -439,10 +457,12 @@ def doc(config="doxygen.conf.in", projectName=None, projectNumber=None, **kw): | |
## | ||
@staticmethod | ||
def tests(pyList=None, ccList=None, swigNameList=None, swigSrc=None, | ||
ignoreList=None, noBuildList=None, | ||
ignoreList=None, noBuildList=None, pySingles=None, | ||
args=None): | ||
if noBuildList is None: | ||
noBuildList = [] | ||
if pySingles is None: | ||
pySingles = [] | ||
if swigNameList is None: | ||
swigFileList = Glob("*.i") | ||
swigNameList = [_getFileBase(node) for node in swigFileList] | ||
|
@@ -459,6 +479,10 @@ def tests(pyList=None, ccList=None, swigNameList=None, swigSrc=None, | |
pyList = [node for node in Glob("*.py") | ||
if _getFileBase(node) not in swigNameList and | ||
os.path.basename(str(node)) not in noBuildList] | ||
# if we got no matches, reset to None so we do not enabled | ||
# auto test detection in pytest | ||
if not pyList: | ||
pyList = None | ||
if ccList is None: | ||
ccList = [node for node in Glob("*.cc") | ||
if (not str(node).endswith("_wrap.cc")) and str(node) not in allSwigSrc and | ||
|
@@ -467,7 +491,10 @@ def tests(pyList=None, ccList=None, swigNameList=None, swigSrc=None, | |
ignoreList = [] | ||
|
||
def s(l): | ||
if l is None: | ||
return ['None'] | ||
return [str(i) for i in l] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is prior formatting but a newline would be nice here to visually separate the function block. I'm surprised that flake8 doesn't catch nested functions. |
||
|
||
state.log.info("SWIG modules for tests: %s" % s(swigFileList)) | ||
state.log.info("Python tests: %s" % s(pyList)) | ||
state.log.info("C++ tests: %s" % s(ccList)) | ||
|
@@ -481,9 +508,31 @@ def s(l): | |
swigMods.extend( | ||
state.env.SwigLoadableModule("_" + name, src, LIBS=state.env.getLibs("main python")) | ||
) | ||
|
||
# Warn about insisting that a test in pySingles starts with test_ and | ||
# therefore might be automatically discovered by pytest. These files | ||
# should not be discovered automatically. | ||
for node in pySingles: | ||
if str(node).startswith("test_"): | ||
state.log.warn("Warning: {} should be run independently but" | ||
" can be automatically discovered".format(node)) | ||
|
||
# Ensure that python tests listed in pySingles are not included in pyList. | ||
if pyList is not None: | ||
pyList = [str(node) for node in pyList if str(node) not in pySingles] | ||
|
||
ccList = [control.run(str(node)) for node in ccList] | ||
pyList = [control.run(str(node)) for node in pyList] | ||
pySingles = [control.run(str(node)) for node in pySingles] | ||
|
||
# If we tried to discover .py files and found none, do not then | ||
# try to use auto test discovery. | ||
if pyList is not None: | ||
pyList = [control.runPythonTests(pyList)] | ||
else: | ||
pyList = [] | ||
pyList.extend(pySingles) | ||
for pyTest in pyList: | ||
state.env.Depends(pyTest, ccList) | ||
state.env.Depends(pyTest, swigMods) | ||
state.env.Depends(pyTest, state.targets["python"]) | ||
state.env.Depends(pyTest, state.targets["shebang"]) | ||
|
@@ -533,4 +582,4 @@ def examples(ccList=None, swigNameList=None, swigSrc=None): | |
state.targets["examples"].extend(results) | ||
return results | ||
|
||
## @} | ||
## @} # noqa E266 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will the cache file show up here (at the package root) when scons runs pytest? In the past I think it may have showed up in
tests/.cache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems to in this case. This will ignore all directories named
.cache
so it will work either way.