Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit bacb396

Browse files
committed
Fix: Report profile output at end of test run.
1 parent e36b729 commit bacb396

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

tests/ci_utils.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Standard library
1111
# ----------------
1212
from __future__ import print_function
13-
from subprocess import check_call
13+
from subprocess import run
1414
import sys
1515
import os
1616
import os.path
@@ -24,19 +24,22 @@
2424

2525
# Copied from https://docs.python.org/3.5/library/platform.html#cross-platform.
2626
is_64bits = sys.maxsize > 2**32
27-
#
27+
28+
2829
# Support code
2930
# ============
3031
# xqt
3132
# ---
3233
# Pronounced "execute": provides a simple way to execute a system command.
3334
def xqt(
34-
# Commands to run. For example, ``'foo -param firstArg secondArg', 'bar |
35-
# grep alpha'``.
36-
*cmds,
37-
# Optional keyword arguments to pass on to `subprocess.check_call <https://docs.python.org/3/library/subprocess.html#subprocess.check_call>`_.
38-
**kwargs):
35+
# Commands to run. For example, ``'foo -param firstArg secondArg', 'bar |
36+
# grep alpha'``.
37+
*cmds,
38+
# Optional keyword arguments to pass on to `subprocess.check_call <https://docs.python.org/3/library/subprocess.html#subprocess.check_call>`_.
39+
**kwargs
40+
):
3941

42+
ret = []
4043
# Although https://docs.python.org/3/library/subprocess.html#subprocess.Popen
4144
# states, "The only time you need to specify ``shell=True`` on Windows is
4245
# when the command you wish to execute is built into the shell (e.g.
@@ -55,15 +58,21 @@ def xqt(
5558
# works. See https://docs.python.org/3/library/subprocess.html#subprocess.Popen.
5659
executable = ('/bin/bash' if is_linux or is_darwin
5760
else None)
58-
check_call(_, shell=True, executable=executable, **kwargs)
59-
#
61+
ret.append(run(_, shell=True, capture_output=True,
62+
executable=executable, **kwargs))
63+
64+
# Return a list only if there were multiple commands to execute.
65+
return ret[0] if len(ret) == 1 else ret
66+
67+
6068
# pushd
6169
# -----
6270
# A context manager for pushd.
6371
class pushd:
6472
def __init__(self,
65-
# The path to change to upon entering the context manager.
66-
path):
73+
# The path to change to upon entering the context manager.
74+
path
75+
):
6776

6877
self.path = path
6978

@@ -76,7 +85,8 @@ def __exit__(self, type_, value, traceback):
7685
flush_print('popd - returning to {}.'.format(self.cwd))
7786
os.chdir(self.cwd)
7887
return False
79-
#
88+
89+
8090
# Common tools
8191
# ============
8292
#
@@ -85,13 +95,15 @@ def __exit__(self, type_, value, traceback):
8595
def chdir(path):
8696
flush_print('cd ' + path)
8797
os.chdir(path)
88-
#
98+
99+
89100
# mkdir
90101
# -----
91102
def mkdir(path):
92103
flush_print('mkdir ' + path)
93104
os.mkdir(path)
94-
#
105+
106+
95107
# flush_print
96108
# -----------
97109
# Anything sent to ``print`` won't be printed until Python flushes its buffers,
@@ -102,14 +114,16 @@ def flush_print(*args, **kwargs):
102114
# Flush both buffers, just in case there's something in ``stdout``.
103115
sys.stdout.flush()
104116
sys.stderr.flush()
105-
#
117+
118+
106119
# isfile
107120
# ------
108121
def isfile(f):
109122
_ = os.path.isfile(f)
110123
flush_print('File {} {}.'.format(f, 'exists' if _ else 'does not exist'))
111124
return _
112-
#
125+
126+
113127
# isfile
114128
# ------
115129
def isdir(f):

tests/conftest.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ def pytest_addoption(parser):
6464
help='Skip W3C validation of web pages.')
6565

6666

67+
# Output a coverage report when testing is done. See https://docs.pytest.org/en/latest/reference.html#_pytest.hookspec.pytest_terminal_summary.
68+
def pytest_terminal_summary(terminalreporter):
69+
with pushd('../../..'):
70+
cp = xqt('{} -m coverage report'.format(sys.executable), text=True)
71+
terminalreporter.write_line(cp.stdout + cp.stderr)
72+
73+
74+
6775
# Utilities
6876
# =========
6977
# A simple data-struct object.
@@ -219,8 +227,6 @@ def echo():
219227
web2py_scheduler.terminate()
220228
echo_thread.join()
221229

222-
xqt('{} -m coverage report'.format(sys.executable))
223-
224230

225231
# The name of the Runestone controller. It must be module scoped to allow the ``web2py_server`` to use it.
226232
@pytest.fixture(scope='session')

0 commit comments

Comments
 (0)