PythonUnitTest

The PythonUnitTest tester is used to run Python scripts in the MOOSE test suite. These are usually unit tests, but can also be running a Method of Manufactured solutions study. The test passes if the python scripts returns normally, and fails if an error/exception is met.

commentnote

Recover testing and valgrind memory-checking is disabled by default for the PythonUnitTest.

Options

Test configuration options are specified in the tests file.

  • input: The python input file to use for this test

  • test_case: The specific test case to run. Defaults to all test cases in the module

  • buffer: Equivalent to passing -b or --buffer to the unittest. Defaults to False

  • separate: Run each test in the file in a separate subprocess. Defaults to False

Other test commands & restrictions may be found in the TestHarness documentation.

Example test configuration in the MOOSE test suite

In this example, PythonUnitTests are used to perform method of manufactured solutions studies of advection outflow boundary conditions with a finite volume discretization. The python mms scripts can compute the order of convergence of the mesh by running multiple simulations with increasing discretization. They then check this convergence against the expected discretization. If the desired order of convergence is not met, the scripts error out, which is caught by the tester.

[Tests]
  design = 'fv_design.md'
  [test]
    type = Exodiff
    input = advection-diffusion.i
    exodiff = advection-diffusion_out.e
    requirement = 'The system shall be able to to solve an advection-diffusion equation with a dirichlet condition on the left boundary and a zero gradient condition on the right boundary and display second order convergence with the finite volume method.'
    issues = '#14549'
  []
  [outflow]
    requirement = 'The system shall, while using an advective outflow boundary condition, demonstrate second order convergence if a two term Taylor series is used to approximate boundary face values and reduced order convergence if a one term Taylor series is used. These converges rates shall be observed with'
    issues = '#14549 #24466'
    [average]
      type = PythonUnitTest
      input = test.py
      test_case = TestOutflow
      required_python_packages = 'pandas matplotlib'
      method = '!dbg'
      installation_type = in_tree # see #26480
      detail = 'a weighted averaging advection interpolation, and'
    []
    [minmod]
      type = PythonUnitTest
      input = test.py
      test_case = TestOutflowMinMod
      required_python_packages = 'pandas matplotlib'
      method = '!dbg'
      installation_type = in_tree # see #26480
      detail = 'a min-mod advection interpolation scheme.'
      min_parallel = 2 # Test geometric and algebraic ghosting
    []
  []
  [extrapolate]
    type = PythonUnitTest
    input = test.py
    test_case = TestExtrapolation
    issues = '#16169 #14549'
    requirement = 'The system shall be able to do one-term and two-term Taylor expansions for extrapolating finite volume solutions to boundary faces, and these extrapolations should be usable by flux kernels at inflow/outflow boundaries to produce first and second order accurate solutions respectively as measured by an L2 norm.'
    required_python_packages = 'pandas matplotlib'
    method = '!dbg'
    installation_type = in_tree # see #26480
  []
  [UpwindLimiter]
    type = PythonUnitTest
    input = test.py
    test_case = UpwindLimiter
    required_python_packages = 'pandas matplotlib'
    requirement = 'The system shall display first order convergence with an upwind limiter.'
    method = '!dbg'
    issues = '#14549'
    installation_type = in_tree # see #26480
  []
  [CentralDifferenceLimiter]
    type = PythonUnitTest
    input = test.py
    test_case = CentralDifferenceLimiter
    required_python_packages = 'pandas matplotlib'
    requirement = 'The system shall display second order convergence with a central-differencing limiter.'
    method = '!dbg'
    issues = '#14549'
    installation_type = in_tree # see #26480
  []
  [VanLeerLimiter]
    type = PythonUnitTest
    input = test.py
    test_case = VanLeerLimiter
    required_python_packages = 'pandas matplotlib'
    requirement = 'The system shall display second order convergence with a Van-Leer limiter.'
    method = '!dbg'
    issues = '#14549'
    installation_type = in_tree # see #26480
  []
  [MinModLimiter]
    type = PythonUnitTest
    input = test.py
    test_case = MinModLimiter
    required_python_packages = 'pandas matplotlib'
    requirement = 'The system shall display second order convergence with a min-mod limiter.'
    method = '!dbg'
    issues = '#14549'
    installation_type = in_tree # see #26480
  []
  [SOULimiter]
    type = PythonUnitTest
    input = test.py
    test_case = SOULimiter
    required_python_packages = 'pandas matplotlib'
    requirement = 'The system shall display second order convergence with a second-order-upwind limiter.'
    method = '!dbg'
    issues = '#14549'
    installation_type = in_tree # see #26480
  []
  [QUICKLimiter]
    type = PythonUnitTest
    input = test.py
    test_case = QUICKLimiter
    required_python_packages = 'pandas matplotlib'
    requirement = 'The system shall display second order convergence with a QUICK limiter.'
    heavy = true
    issues = '#14549'
    installation_type = in_tree # see #26480
  []
  [kt]
    requirement = 'The system shall provide a Kurganov-Tadmor scheme for evaluating convective intercell fluxes'
    issues = '#14549'
    [KTLimitedCD]
      type = PythonUnitTest
      input = test.py
      test_case = KTLimitedCD
      required_python_packages = 'pandas matplotlib'
      detail = 'with central difference interpolation of face values and resulting second order convergence'
      method = '!dbg'
      installation_type = in_tree # see #26480
    []
    [KTLimitedUpwind]
      type = PythonUnitTest
      input = test.py
      test_case = KTLimitedUpwind
      required_python_packages = 'pandas matplotlib'
      detail = 'with upwind interpolation of face values and resulting first order convergence'
      method = '!dbg'
      installation_type = in_tree # see #26480
    []
    [KTLimitedVanLeer]
      type = PythonUnitTest
      input = test.py
      test_case = KTLimitedVanLeer
      required_python_packages = 'pandas matplotlib'
      detail = 'with central difference interpolation with Van-Leer limiting of face values and resulting two and a half order convergence' # I don't actually know where this additional half order is coming from
      method = '!dbg'
      installation_type = in_tree # see #26480
    []
  []
[]
(contrib/moose/test/tests/fvkernels/mms/advective-outflow/tests)