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

Automatic test discovery sans boilerplate #1693

Merged
merged 58 commits into from
Oct 13, 2021

Conversation

Helveg
Copy link
Collaborator

@Helveg Helveg commented Sep 29, 2021

adresses #1687, closes #1463.

Removed all of the verbose deprecated boiler plate in favor of automatic discovery.

Threw in a little fixture system for extra points:

from .. import fixtures

@fixtures.context
@fixtures.empty_recipe
def test_something(context, empty_recipe):
  arbor.simulation(empty_recipe, context)

If anyone wants to add fixtures all they have to do is write a function/class in python/test/fixtures.py and decorate it with the internal _fixture or _singleton_fixture decorators. Then they can be used in test files as decorators that inject parameters with their name like in the example above:

@_fixture
class empty_recipe(arbor.recipe):
    pass

Fixtures added:

  • @repo_path returns the pathlib.Path to the repo root
  • @context returns an arbor.context with MPI (if enabled) and `mpi4py comm (if enabled). Auto inits MPI.
  • @dummy_catalogue returns an arbor.catalogue with the dummy mech in it, uses build-catalogue, builds under MPI on one node, doesn't stall if there's build errors.
  • @empty_recipe returns an instance of an arbor.recipe without anything defined in it.

@Helveg
Copy link
Collaborator Author

Helveg commented Oct 4, 2021

I require to build catalogues in CI, which overlaps with #1632, so I merged it in and will merge master once that PR is merged.

doc/contrib/test.rst Outdated Show resolved Hide resolved
doc/contrib/test.rst Outdated Show resolved Hide resolved
python/test/unit/test_clear_samplers.py Show resolved Hide resolved
@Helveg
Copy link
Collaborator Author

Helveg commented Oct 11, 2021

I added cases.py as a centralized location for modifying TestCases and added some skip decorators that should replace the old seperate runs of unit and unit_distributed. Advantages are that unmarked tests are now run both with and without MPI and you can just run the suite and it will detect whether it can run MPI tests by itself, skipping appropriately:

# Skips all MPI only tests
python -m unittest discover -s python
# Skips all no-MPI only tests
mpiexec -n 2 python -m unittest discover -s python

Disadvantages are that tests that run exclusively with/without MPI need to be marked explicitly with the decorators, but that's 1 line of code per file.

mechanisms/default/nax.mod Outdated Show resolved Hide resolved
python/test/fixtures.py Show resolved Hide resolved
Copy link
Contributor

@thorstenhater thorstenhater left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@brenthuisman brenthuisman merged commit d4d8ced into arbor-sim:master Oct 13, 2021
@Helveg Helveg deleted the python/clean-unittest branch October 13, 2021 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python unit test cleanup
4 participants