dirnames = [dirname] + extra_test_dirs
pref_filed, pref_filename = tempfile.mkstemp("brian_prefs", text=True)
pref_file = os.fdopen(pref_filed, "w")
print("Running tests in %s " % (", ".join(dirnames)), end="")
if codegen_targets:
print("for targets %s" % (", ".join(codegen_targets)), end="")
ex_in = "including" if long_tests else "excluding"
print(" (%s long tests)" % ex_in)
print("Running Brian version {} "
"from "{}"".format(brian2.__version__,
os.path.dirname(brian2.__file__)))
all_targets = set(codegen_targets)
if test_standalone:
if not isinstance(test_standalone, basestring):
raise ValueError("test_standalone argument has to be the name of a "
"standalone device (e.g. "cpp_standalone")")
if test_standalone not in all_devices:
raise ValueError("test_standalone argument "%s" is not a known "
"device. Known devices are: "
"%s" % (test_standalone,
", ".join(repr(d) for d in all_devices)))
print("Testing standalone")
all_targets.add(test_standalone)
if test_codegen_independent:
print("Testing codegen-independent code")
all_targets.add("codegen_independent")
parallel_tests = all_targets.intersection(set(test_in_parallel))
if parallel_tests:
try:
import xdist
print("Testing with multiple processes for %s" % ", ".join(
parallel_tests))
except ImportError:
test_in_parallel = []
if reset_preferences:
print("Resetting to default preferences")
if reset_preferences:
stored_prefs = prefs.as_file
prefs.read_preference_file(StringIO(prefs.defaults_as_file))
// Avoid failures in the tests for user-registered units
import copy
import brian2.units.fundamentalunits as fundamentalunits
old_unit_registry = copy.copy(fundamentalunits.user_unit_register)
fundamentalunits.user_unit_register = fundamentalunits.UnitRegistry()
if float_dtype is not None:
print("Setting dtype for floating point variables to: "
"{}".format(float_dtype.__name__))
prefs["core.default_float_dtype"] = float_dtype
print()
// Suppress INFO log messages during testing
from brian2.utils.logger import BrianLogger, LOG_LEVELS
log_level = BrianLogger.console_handler.level
BrianLogger.console_handler.setLevel(LOG_LEVELS["WARNING"])
// Switch off code optimization to get faster compilation times
prefs["codegen.cpp.extra_compile_args_gcc"].extend(["-w", "-O0"])
prefs["codegen.cpp.extra_compile_args_msvc"].extend(["-w", "-O0"])
// if fail_for_not_implemented:
// not_implemented_plugin = NotImplementedPlugin
// else:
// not_implemented_plugin = NotImplementedNoFailurePlugin
// // This hack is needed to get the NotImplementedPlugin working for multiprocessing
// import nose.plugins.multiprocess as multiprocess
// multiprocess._instantiate_plugins = [not_implemented_plugin]
//
// plugins = [not_implemented_plugin()]
from brian2.devices import set_device
set_device("runtime")
pref_plugin = PreferencePlugin(prefs)
try:
success = []
if test_codegen_independent:
print("Running tests that do not use code generation")
// Some doctests do actually use code generation, use numpy for that
prefs["codegen.target"] = "numpy"
// Print output changed in numpy 1.14, stick with the old format to
// avoid doctest failures
import numpy as np
try:
np.set_printoptions(legacy="1.13")
except TypeError:
pass // using a numpy version < 1.14
argv = make_argv(dirnames, "codegen_independent")
if "codegen_independent" in test_in_parallel:
argv.extend(multiprocess_arguments)
// multiprocess._instantiate_plugins.append(OurDoctestPlugin)
print("executing with", argv)
pref_file.truncate(0)
pref_file.write(prefs.as_file)
pref_file.flush()
success.append(pytest.main(argv, plugins=[pref_plugin]) == 0)
// if "codegen_independent" in test_in_parallel:
// multiprocess._instantiate_plugins.remove(OurDoctestPlugin)
After Change
// Some doctests do actually use code generation, use numpy for that
prefs["codegen.target"] = "numpy"
argv = make_argv(dirnames, doctests=True)
if "codegen_independent" in test_in_parallel:
argv.extend(multiprocess_arguments)
success.append(pytest.main(argv, plugins=[pref_plugin]) == 0)
print("Running tests that do not use code generation")
argv = make_argv(dirnames, "codegen_independent")