X Tutup
Skip to content

Commit b2e7e7e

Browse files
authored
Recover coverage from subprocesses during unit tests (spack#15354)
* Recover coverage from subprocesses during unit tests
1 parent dd8afca commit b2e7e7e

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

lib/spack/spack/cmd/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def test(parser, args, unknown_args):
154154

155155
# The default is to test the core of Spack. If the option `--extension`
156156
# has been used, then test that extension.
157-
pytest_root = spack.paths.test_path
157+
pytest_root = spack.paths.spack_root
158158
if args.extension:
159159
target = args.extension
160160
extensions = spack.config.get('config:extensions')

lib/spack/spack/test/cmd/test.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from spack.main import SpackCommand
77

88
spack_test = SpackCommand('test')
9+
cmd_test_py = 'lib/spack/spack/test/cmd/test.py'
910

1011

1112
def test_list():
@@ -16,13 +17,13 @@ def test_list():
1617

1718

1819
def test_list_with_pytest_arg():
19-
output = spack_test('--list', 'cmd/test.py')
20-
assert output.strip() == "cmd/test.py"
20+
output = spack_test('--list', cmd_test_py)
21+
assert output.strip() == cmd_test_py
2122

2223

2324
def test_list_with_keywords():
2425
output = spack_test('--list', '-k', 'cmd/test.py')
25-
assert output.strip() == "cmd/test.py"
26+
assert output.strip() == cmd_test_py
2627

2728

2829
def test_list_long(capsys):
@@ -44,7 +45,7 @@ def test_list_long(capsys):
4445

4546
def test_list_long_with_pytest_arg(capsys):
4647
with capsys.disabled():
47-
output = spack_test('--list-long', 'cmd/test.py')
48+
output = spack_test('--list-long', cmd_test_py)
4849
assert "test.py::\n" in output
4950
assert "test_list" in output
5051
assert "test_list_with_pytest_arg" in output
@@ -74,7 +75,7 @@ def test_list_names():
7475

7576

7677
def test_list_names_with_pytest_arg():
77-
output = spack_test('--list-names', 'cmd/test.py')
78+
output = spack_test('--list-names', cmd_test_py)
7879
assert "test.py::test_list\n" in output
7980
assert "test.py::test_list_with_pytest_arg\n" in output
8081
assert "test.py::test_list_with_keywords\n" in output

lib/spack/spack/test/llnl/util/log.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def test_log_python_output_with_fd_stream(capfd, tmpdir):
3232
with open('foo.txt') as f:
3333
assert f.read() == 'logged\n'
3434

35-
assert capfd.readouterr() == ('', '')
35+
# Coverage is cluttering stderr during tests
36+
assert capfd.readouterr()[0] == ''
3637

3738

3839
def test_log_python_output_and_echo_output(capfd, tmpdir):
@@ -42,7 +43,8 @@ def test_log_python_output_and_echo_output(capfd, tmpdir):
4243
print('echo')
4344
print('logged')
4445

45-
assert capfd.readouterr() == ('echo\n', '')
46+
# Coverage is cluttering stderr during tests
47+
assert capfd.readouterr()[0] == 'echo\n'
4648

4749
with open('foo.txt') as f:
4850
assert f.read() == 'echo\nlogged\n'
@@ -75,7 +77,8 @@ def test_log_subproc_and_echo_output(capfd, tmpdir):
7577
echo('echo')
7678
print('logged')
7779

78-
assert capfd.readouterr() == ('echo\n', '')
80+
# Coverage is cluttering stderr during tests
81+
assert capfd.readouterr()[0] == 'echo\n'
7982

8083
with open('foo.txt') as f:
8184
assert f.read() == 'logged\n'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# content of pytest.ini
22
[pytest]
33
addopts = --durations=20 -ra
4-
testpaths = .
4+
testpaths = lib/spack/spack/test
55
python_files = *.py
66
markers =
77
db: tests that require creating a DB

share/spack/qa/run-unit-tests

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,12 @@ bin/spack -h
3737
bin/spack help -a
3838

3939
# Profile and print top 20 lines for a simple call to spack spec
40-
bin/spack -p --lines 20 spec mpileaks%gcc ^elfutils@0.170
40+
spack -p --lines 20 spec mpileaks%gcc ^elfutils@0.170
4141

4242
#-----------------------------------------------------------
4343
# Run unit tests with code coverage
4444
#-----------------------------------------------------------
45-
extra_args=""
46-
if [[ -n "$@" ]]; then
47-
extra_args="-k $@"
48-
fi
49-
$coverage_run bin/spack test -x --verbose "$extra_args"
45+
$coverage_run $(which spack) test -x --verbose
5046

5147
#-----------------------------------------------------------
5248
# Run tests for setup-env.sh

0 commit comments

Comments
 (0)
X Tutup