Skip to content
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

Introduce a way to run tests in parallel #1171

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

### 37.0.1 [#1171](https://github.com/openfisca/openfisca-core/pull/1171)

#### Technical changes

- Introduce option `--workers` to `openfisca test to run tests in parallel`.
- Check `openfisca test --help` for usage instructions.
- Add short option `-g` to `openfisca` as a synonym to `--performance-graph`.

# 37.0.0 [#1142](https://github.com/openfisca/openfisca-core/pull/1142)

#### Deprecations
Expand Down
92 changes: 82 additions & 10 deletions openfisca_core/scripts/openfisca_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,89 @@ def build_serve_parser(parser):
parser_serve = build_serve_parser(parser_serve)

def build_test_parser(parser):
parser.add_argument('path', help = "paths (files or directories) of tests to execute", nargs = '+')
parser.add_argument("path", help = "paths (files or directories) of tests to execute", nargs = "+")

parser = add_tax_benefit_system_arguments(parser)
parser.add_argument('-n', '--name_filter', default = None, help = "partial name of tests to execute. Only tests with the given name_filter in their name, file name, or keywords will be run.")
parser.add_argument('-p', '--pdb', action = 'store_true', default = False, help = "drop into debugger on failures or errors")
parser.add_argument('--performance-graph', '--performance', action = 'store_true', default = False, help = "output a performance graph in a 'performance_graph.html' file")
parser.add_argument('--performance-tables', action = 'store_true', default = False, help = "output performance CSV tables")
parser.add_argument('-v', '--verbose', action = 'store_true', default = False, help = "increase output verbosity. If specified, output the entire calculation trace.")
parser.add_argument('-a', '--aggregate', action = 'store_true', default = False, help = "increase output verbosity to aggregate. If specified, output the avg, max, and min values of the calculation trace. This flag has no effect without --verbose.")
parser.add_argument('-d', '--max-depth', type = int, default = None, help = "set maximal verbosity depth. If specified, output the calculation trace up to the provided depth. This flag has no effect without --verbose.")
parser.add_argument('-o', '--only-variables', nargs = '*', default = None, help = "variables to test. If specified, only test the given variables.")
parser.add_argument('-i', '--ignore-variables', nargs = '*', default = None, help = "variables to ignore. If specified, do not test the given variables.")

parser.add_argument(
"-a",
"--aggregate",
action = "store_true",
default = False,
help = "increase output verbosity to aggregate. If specified, output the avg, max, and min values of the calculation trace. This flag has no effect without --verbose.",
)

parser.add_argument(
"-d",
"--max-depth",
type = int,
default = None,
help = "set maximal verbosity depth. If specified, output the calculation trace up to the provided depth. This flag has no effect without --verbose.",
)

parser.add_argument(
"-g",
"--performance-graph",
"--performance",
action = "store_true",
default = False,
help = "output a performance graph in a 'performance_graph.html' file",
)

parser.add_argument(
"-i",
"--ignore-variables",
nargs = "*",
default = None,
help = "variables to ignore. If specified, do not test the given variables.",
)

parser.add_argument(
"-n",
"--name_filter",
default = None,
help = "partial name of tests to execute. Only tests with the given name_filter in their name, file name, or keywords will be run.",
)

parser.add_argument(
"-o",
"--only-variables",
nargs = "*",
default = None,
help = "variables to test. If specified, only test the given variables.",
)

parser.add_argument(
"-p",
"--pdb",
action = "store_true",
default = False,
help = "drop into debugger on failures or errors",
)

parser.add_argument(
"-t",
"--performance-tables",
action = "store_true",
default = False,
help = "output performance CSV tables",
)

parser.add_argument(
"-v",
"--verbose",
action = "store_true",
default = False,
help = "increase output verbosity. If specified, output the entire calculation trace.",
)

parser.add_argument(
"-w",
"--workers",
nargs = 1,
default = "auto",
help = "run tests distributed per core. Use `auto` to detect the number of cores.",
)

return parser

Expand Down
19 changes: 10 additions & 9 deletions openfisca_core/scripts/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ def main(parser):
tax_benefit_system = build_tax_benefit_system(args.country_package, args.extensions, args.reforms)

options = {
'pdb': args.pdb,
'performance_graph': args.performance_graph,
'performance_tables': args.performance_tables,
'verbose': args.verbose,
'aggregate': args.aggregate,
'max_depth': args.max_depth,
'name_filter': args.name_filter,
'only_variables': args.only_variables,
'ignore_variables': args.ignore_variables,
"aggregate": args.aggregate,
"ignore_variables": args.ignore_variables,
"max_depth": args.max_depth,
"name_filter": args.name_filter,
"only_variables": args.only_variables,
"pdb": args.pdb,
"performance_graph": args.performance_graph,
"performance_tables": args.performance_tables,
"verbose": args.verbose,
"workers": args.workers,
}

paths = [os.path.abspath(path) for path in args.path]
Expand Down
5 changes: 5 additions & 0 deletions openfisca_core/tools/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Options(TypedDict, total = False):
performance_graph: bool
performance_tables: bool
verbose: bool
workers: Optional[Sequence[str]]


@dataclasses.dataclass(frozen = True)
Expand Down Expand Up @@ -130,6 +131,7 @@ def run_tests(
"""

argv = []
workers = options.get("workers")
plugins = [OpenFiscaPlugin(tax_benefit_system, options)]

if options.get('pdb'):
Expand All @@ -138,6 +140,9 @@ def run_tests(
if options.get('verbose'):
argv.append('--verbose')

if workers is not None:
argv.append(f"--workers={workers}")

if isinstance(paths, str):
paths = [paths]

Expand Down
6 changes: 4 additions & 2 deletions openfisca_tasks/test_code.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ test-core: $(shell pytest --quiet --quiet --collect-only 2> /dev/null | cut -f 1
test-country:
@$(call print_help,$@:)
@PYTEST_ADDOPTS="$${PYTEST_ADDOPTS} ${pytest_args}" \
openfisca test ${python_packages}/openfisca_country_template/tests \
python -m \
${openfisca} test ${python_packages}/openfisca_country_template/tests \
--country-package openfisca_country_template \
${openfisca_args}
@$(call print_pass,$@:)
Expand All @@ -54,7 +55,8 @@ test-country:
test-extension:
@$(call print_help,$@:)
@PYTEST_ADDOPTS="$${PYTEST_ADDOPTS} ${pytest_args}" \
openfisca test ${python_packages}/openfisca_extension_template/tests \
python -m \
${openfisca} test ${python_packages}/openfisca_extension_template/tests \
--country-package openfisca_country_template \
--extensions openfisca_extension_template \
${openfisca_args}
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ skip_covered = true
skip_empty = true

[tool:pytest]
addopts = --doctest-modules --disable-pytest-warnings --showlocals
addopts = --disable-pytest-warnings --doctest-modules --showlocals
doctest_optionflags = ELLIPSIS IGNORE_EXCEPTION_DETAIL NUMBER NORMALIZE_WHITESPACE
python_files = **/*.py
testpaths = tests
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@
'mypy == 0.910',
'pycodestyle >= 2.8.0, < 2.9.0',
'pylint == 2.10.2',
'pytest-parallel < 0.2.0',
'xdoctest >= 1.0.0, < 2.0.0',
] + api_requirements

setup(
name = 'OpenFisca-Core',
version = '37.0.0',
version = '37.0.1',
author = 'OpenFisca Team',
author_email = '[email protected]',
classifiers = [
Expand Down