1 of 28

Regression tests in

1

D. Eldon/OMFIT code camp/2019-11-11

2 of 28

Regression tests in OMFIT

Outline

  • Purpose of regression tests
  • Regression test area and tools for loading tests
  • OMFITtest class for reporting test results to GitHub, slack, email
  • Automatic testing and GitHub test status
  • Test small units of code where possible
  • The assert statement

​

2

D. Eldon/OMFIT code camp/2019-11-11

3 of 28

Regression tests in OMFIT

Outline

  • Purpose of regression tests
  • Regression test area and tools for loading tests
  • OMFITtest class for reporting test results to GitHub, slack, email
  • Automatic testing and GitHub test status
  • Test small units of code where possible
  • The assert statement

​

3

D. Eldon/OMFIT code camp/2019-11-11

4 of 28

Write regression tests for scripts in OMFIT to detect problems with proposed changes

  • User wants to merge code that breaks everything
  • Must run a regression test first
  • Test fails & notifies maintainers that new code is problematic
  • Merge is delayed until problems are fixed
  • Your tools are protected

4

D. Eldon/OMFIT code camp/2019-11-11

5 of 28

Regression tests in OMFIT

Outline

  • Purpose of regression tests
  • Regression test area and tools for loading tests
  • OMFITtest class for reporting test results to GitHub, slack, email
  • Automatic testing and GitHub test status
  • Test small units of code where possible
  • The assert statement

​

5

D. Eldon/OMFIT code camp/2019-11-11

6 of 28

Regression test kept in OMFIT-source/regression/

& loaded with convenient GUI

OMFIT has a bunch of tests in this regression/ folder

...

6

D. Eldon/OMFIT code camp/2019-11-11

7 of 28

Regression test kept in OMFIT-source/regression/

& loaded with convenient GUI

Regression scripts can be loaded to the tree with a GUI accessed from OMFIT’s “File” menu

type filter here

7

D. Eldon/OMFIT code camp/2019-11-11

8 of 28

Regression tests can also be run from the command line

omfit regression/test_template.py

...

8

D. Eldon/OMFIT code camp/2019-11-11

9 of 28

Regression tests in OMFIT

Outline

  • Purpose of regression tests
  • Regression test area and tools for loading tests
  • OMFITtest class for reporting test results to GitHub, slack, email
  • Automatic testing and GitHub test status
  • Test small units of code where possible
  • The assert statement

​

9

D. Eldon/OMFIT code camp/2019-11-11

10 of 28

The OMFITtest class is for helping organize and communicate test results

OMFITtest reporting options:

  • Status updates on GitHub
  • Print formatted results tables and exception tracebacks
  • Comment on GitHub, including stuff from print
    • It looks up open pull requests for your branch automatically
  • Slack reports
  • Emailed reports

10

D. Eldon/OMFIT code camp/2019-11-11

11 of 28

The OMFITtest class is for helping organize and communicate test results

  • Get started with OMFITtest by copying TestOmfitMinimal(OMFITtest) out of regression/test_template.py

11

D. Eldon/OMFIT code camp/2019-11-11

12 of 28

The OMFITtest class is for helping organize and communicate test results

  • After copying, rename TestOmfitMinimal to something more descriptive

12

D. Eldon/OMFIT code camp/2019-11-11

13 of 28

The OMFITtest class is for helping organize and communicate test results

  • Then replace the dummy test method with your own tests

13

D. Eldon/OMFIT code camp/2019-11-11

14 of 28

The OMFITtest class is for helping organize and communicate test results

  • manage_tests can take a class or list of classes that are subclassed from OMFITtest
  • If given a list, the group of tests can be run together under one context, or with a set of separate contexts

14

D. Eldon/OMFIT code camp/2019-11-11

15 of 28

OMFITtest settings are written in the top of the class

notify_gh_status

Turns on/off GitHub status updates for the class itself

​

gh_individual_status

concerns status updates for test methods within the class

0: no status posts for methods

1: status posts for methods

2: status posts only for failed test methods

15

D. Eldon/OMFIT code camp/2019-11-11

16 of 28

OMFITtest settings are written in the top of the class

modules_to_load

The test class will load modules under OMFIT and append _test_copy to the key name

​

​

16

D. Eldon/OMFIT code camp/2019-11-11

17 of 28

OMFITtest settings are written in the top of the class

Other testing data

You can define variables for general use in the test, like a device and shot to use by default for most tests.

These are accessed as attributes of self

​

​

17

D. Eldon/OMFIT code camp/2019-11-11

18 of 28

Further examples of OMFITtest usage

  • regression/test_omfit_test.py
  • regression/test_SOLPS.py
  • regression/test_OMFITelm.py
  • Find others by grep OMFITtest -r regression

18

D. Eldon/OMFIT code camp/2019-11-11

19 of 28

Regression tests in OMFIT

Outline

  • Purpose of regression tests
  • Regression test area and tools for loading tests
  • OMFITtest class for reporting test results to GitHub, slack, email
  • Automatic testing and GitHub test status
  • Test small units of code where possible
  • The assert statement

​

19

D. Eldon/OMFIT code camp/2019-11-11

20 of 28

OMFITtest can post GitHub status updates

Status options:

  • pass (green check),
  • fail (red X),
  • pending/expected (yellow dot)

20

D. Eldon/OMFIT code camp/2019-11-11

21 of 28

Required checks help protect the repository from new bugs

  • Each status has a context
    • Example: p2.7 run_test_series@morti.gat.com
  • Some contexts can be set as required
    • Merge is not possible until a passing status is posted for these contexts

21

D. Eldon/OMFIT code camp/2019-11-11

22 of 28

The Macmini Omfit Regression Test Invigilator (morti) runs some tests automatically

  • Tests have labels
  • morti looks at which files change to decide what labels to run
  • morti looks for tests with the matching labels and runs those tests
  • morti’s test results are posted to GitHub with their own status context(s)

22

D. Eldon/OMFIT code camp/2019-11-11

23 of 28

Regression tests in OMFIT

Outline

  • Purpose of regression tests
  • Regression test area and tools for loading tests
  • OMFITtest class for reporting test results to GitHub, slack, email
  • Automatic testing and GitHub test status
  • Test small units of code where possible
  • The assert statement

​

23

D. Eldon/OMFIT code camp/2019-11-11

24 of 28

Tests that focus on small units of code make finding errors easier

  • If using TestAllOfOmfit, where do you start looking for a failure?
    • Giant integration tests are nice when they pass and tell you everything is fine, but potentially less useful when they fail
  • If your test is TestFunction1inMode2, when it fails, you know function1() doesn’t work in mode 2
    • You can immediately narrow your debugging to the specific problem area
    • You can repeat a shorter, faster test after making changes
  • If you set gh_individual_status=2, you will get failed status reports for each individual test method, giving you a list of problems to tackle.
  • OMFITtest prints exception reports to the OMFIT console; one per failed test method.
    • You can get more detailed/granular reports if the tests are split into smaller units.

24

D. Eldon/OMFIT code camp/2019-11-11

25 of 28

Regression tests in OMFIT

Outline

  • Purpose of regression tests
  • Regression test area and tools for loading tests
  • OMFITtest class for reporting test results to GitHub, slack, email
  • Automatic testing and GitHub test status
  • Test small units of code where possible
  • The assert statement

​

25

D. Eldon/OMFIT code camp/2019-11-11

26 of 28

assert is the best statement for tests

26

D. Eldon/OMFIT code camp/2019-11-11

27 of 28

assert is the best statement for tests

27

D. Eldon/OMFIT code camp/2019-11-11

28 of 28

Recommendations for regression testing

  • Write regression tests for everything
  • Write tests in parallel with the things they test
    • Tests can help you develop new scripts
  • Use OMFITtest if you want your results posted on GitHub
    • Or if you want a results table printed, etc.
  • Separate tests into focused functions that are named for the specific things they test
  • Pepper your tests with the assert statement

28

D. Eldon/OMFIT code camp/2019-11-11