Skip to content

Commit

Permalink
Merge pull request #1545 from brian-team/pytest-cov
Browse files Browse the repository at this point in the history
Move to pytest-cov
  • Loading branch information
mstimberg authored Jun 28, 2024
2 parents 888cc57 + 1a73a1f commit 3f88158
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# .coveragerc to control coverage.py
# following the example at http://nedbatchelder.com/code/coverage/config.html
[run]
concurrency = multiprocessing
parallel = True
sigterm = True
relative_files = True
branch = True
source_pkgs = brian2
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- name: Install Brian2 and dependencies
run: |
conda install --quiet --yes pip gsl
python -m pip install .[test] coverage
python -m pip install .[test]
- name: Determine Cython cache dir
id: cython-cache
Expand All @@ -92,9 +92,8 @@ jobs:
- name: Run Tests
run: |
cd $GITHUB_WORKSPACE/.. # move out of the workspace to avoid direct import
coverage run --rcfile=$GITHUB_WORKSPACE/.coveragerc $GITHUB_WORKSPACE/$SCRIPT_NAME
coverage lcov --rcfile=$GITHUB_WORKSPACE/.coveragerc
cp coverage.lcov $GITHUB_WORKSPACE/
python $GITHUB_WORKSPACE/$SCRIPT_NAME
cp coverage.xml $GITHUB_WORKSPACE/
env:
SCRIPT_NAME: dev/continuous-integration/run_test_suite.py
SPHINX_DIR: ${{ github.workspace }}/docs_sphinx
Expand All @@ -106,8 +105,6 @@ jobs:
uses: coverallsapp/[email protected]
with:
parallel: true
format: lcov
file: coverage.lcov
flag-name: run ${{ join(matrix.*, ' - ') }}

coveralls:
Expand Down
4 changes: 4 additions & 0 deletions brian2/tests/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ filterwarnings =
ignore:BaseException:DeprecationWarning
ignore:invalid value:RuntimeWarning
ignore:divide by zero:RuntimeWarning
ignore:overflow:RuntimeWarning

# Fail tests after 10 minutes
timeout = 600
6 changes: 5 additions & 1 deletion brian2/tests/test_cpp_standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,12 @@ def test_change_parameters_multiprocessing():

import multiprocessing

with multiprocessing.Pool() as p:
p = multiprocessing.Pool()
try:
results = p.map(sim.run_sim, range(5))
finally:
p.close()
p.join()

for idx, result in zip(range(5), results):
v, w, x = result
Expand Down
12 changes: 10 additions & 2 deletions brian2/tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ def run_in_process_with_logger(x):
@pytest.mark.codegen_independent
def test_file_logging_multiprocessing():
logger.info("info message before multiprocessing")
p = multiprocessing.Pool()

with multiprocessing.Pool() as p:
try:
p.map(run_in_process, range(3))
finally:
p.close()
p.join()

BrianLogger.file_handler.flush()
assert os.path.isfile(BrianLogger.tmp_log)
Expand All @@ -75,8 +79,12 @@ def test_file_logging_multiprocessing():
def test_file_logging_multiprocessing_with_loggers():
logger.info("info message before multiprocessing")

with multiprocessing.Pool() as p:
p = multiprocessing.Pool()
try:
log_files = p.map(run_in_process_with_logger, range(3))
finally:
p.close()
p.join()

BrianLogger.file_handler.flush()
assert os.path.isfile(BrianLogger.tmp_log)
Expand Down
2 changes: 0 additions & 2 deletions brian2/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,6 @@ def initialize():
# interface...
warn_logger = logging.getLogger("py.warnings")
warn_logger.addHandler(BrianLogger.console_handler)
if BrianLogger.file_handler is not None:
warn_logger.addHandler(BrianLogger.file_handler)

# Put some standard info into the log file
logger.log(
Expand Down
16 changes: 14 additions & 2 deletions dev/continuous-integration/run_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# Importing multiprocessing here seems to fix hangs in the test suite on OS X
# see https://github.com/scipy/scipy/issues/11835
import multiprocessing
# Prevent potential issues on multi-threaded execution
multiprocessing.set_start_method('spawn', force=True)
import os
import sys

Expand All @@ -20,7 +22,6 @@
operating_system = os.environ.get('AGENT_OS', 'unknown').lower()
cross_compiled = os.environ.get('CROSS_COMPILED', 'FALSE').lower() in ['yes', 'true']
do_not_reset_preferences = os.environ.get('DO_NOT_RESET_PREFERENCES', 'false').lower() in ['yes', 'true']
report_coverage = os.environ.get('REPORT_COVERAGE', 'no').lower() in ['yes', 'true']
dtype_32_bit = os.environ.get('FLOAT_DTYPE_32', 'no').lower() in ['yes', 'true']
sphinx_dir = os.environ.get('SPHINX_DIR')
src_dir = os.environ.get('SRCDIR')
Expand Down Expand Up @@ -54,7 +55,18 @@
if deprecation_error:
args = ['-W', 'error::DeprecationWarning', '--tb=short']
else:
args = []
# Use coverage when running on GitHub
if "GITHUB_WORKSPACE" in os.environ:
args = [
"--cov",
"--cov-append",
"--cov-report",
"xml",
"--cov-report",
"term",
"--cov-config",
os.path.join(os.environ["GITHUB_WORKSPACE"], ".coveragerc"),
]

if standalone:
result = brian2.test([],
Expand Down
2 changes: 1 addition & 1 deletion numpy2.pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ classifiers = [
]

[project.optional-dependencies]
test = ['pytest', 'pytest-xdist>=1.22.3']
test = ['pytest', 'pytest-xdist>=1.22.3', 'pytest-cov>=2.0', 'pytest-timeout']
docs = ['sphinx>=7', 'ipython>=5', 'sphinx-tabs']

[project.urls]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ classifiers = [
]

[project.optional-dependencies]
test = ['pytest', 'pytest-xdist>=1.22.3']
test = ['pytest', 'pytest-xdist>=1.22.3', 'pytest-cov>=2.0', 'pytest-timeout']
docs = ['sphinx>=7', 'ipython>=5', 'sphinx-tabs']

[project.urls]
Expand Down

0 comments on commit 3f88158

Please sign in to comment.