Skip to content

Introduce a way to run test in parallel #1025

@benoit-cty

Description

@benoit-cty

Hi there!

I really enjoy OpenFisca, but I recently encountered an issue.

Here is what I did:

openfisca test --country-package openfisca_france tests

Here is what I expected to happen:

Use of all the core of my CPU to run test so that it took less than 3 minutes.

Here is what actually happened:

Only one core is used, so test took 17 minutes.

Context

I identify more as a:

Experimentation I have made

Use GNU parallel

find tests/**/*.{yaml,yml} | parallel -j 32 --progress openfisca test --country-package openfisca_france | grep FAILED
Pros:

  • it is really fast, less than 3 minutes.
    Cons:
  • All the test output is printed to the console, so you need to process them to know error, with grep FAILED for example.
  • Need an install at OS level sudo apt-get install parallel.

Use of Xdist

pytest-xdist is a Pytest plugins that run test in parallel.
To use it:
pip install pytest-xdist[psutil]
Add in setup.cfg:

[tool:pytest]
addopts      = -n auto` 

Run the test
openfisca test --country-package openfisca_france tests

openfisca test  --country-package openfisca_france tests
=================================================================================================== test session starts ====================================================================================================
platform linux -- Python 3.8.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /LEXIMPACT/openfisca-france, configfile: setup.cfg
plugins: forked-1.3.0, xdist-2.3.0
gw0 [42] / gw1 [42] / gw2 [42] / gw3 [42] / gw4 [42] / gw5 [42] / gw6 [42] / gw7 [42] / gw8 [42] / gw9 [42] / gw10 [42] / gw11 [42] / gw12 [42] / gw13 [42] / gw14 [42] / gw15 [42]
..........................................
============================================================================================ 42 passed, 1522 warnings in 16.44s ============================================================================================

Pros:

  • Use all CPU core
  • Nice pytest output
    Cons:
  • Need to upgrade pytest version dependencies
  • Don't work as expected : it run the test of the project like a normal pytest, not the OpenFisca YAML testfiles.

It seems that the OpenFisca pytest plugin https://github.com/openfisca/openfisca-core/blob/master/openfisca_core/tools/test_runner.py need to override some xdist method to give it the right test.

Use pytest-parallel

https://github.com/browsertron/pytest-parallel
Not tested, it seems to work like Xdist, so may have the same problem.

Metadata

Metadata

Assignees

Labels

kind:ciContinuous ops, integration & deployment

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions