RelationalAI-oss / XUnit.jl

XUnit.jl is a unit-testing framework for Julia.
MIT License
47 stars 5 forks source link

How to stop testing after the first failed test? #12

Open mdashti opened 3 years ago

mdashti commented 3 years ago

Before we refactored the testing infrastructure, part of my debugging process was to run the tests until they failed at the first test, inspect the stacktrace, and then fix that issue, slowly moving through the tests. However, this is not the new behavior of the testing framework; now, all tests run, regardless of exceptions being thrown. If any tests fail, stacktraces will be issued for all of them.

That is certainly the desired behavior on Hydra (since you want to see all the tests that failed), but in the Julia REPL this actually is a really bad workflow, since finding the first stacktrace can be pretty hard.

Is there a way that we can set the testing infrastructure up so that when tests are run from inside a REPL, by default we choose to stop testing at the first exception?

In addition, the output from a test often ends up separated from exceptions. Consider this example:

...
    Running ExtML mlpack tests/pca_and_kernel_pca_tests/simple_kernel_pca_test at test/ExtML/mlpack.jl:988 tests...
      Running ExtML mlpack tests/pca_and_kernel_pca_tests/simple_kernel_pca_test at test/ExtML/mlpack.jl:988/simple_kernel_pca_test at test/ExtML/mlpack.jl:988 tests...
    Running ExtML mlpack tests/pca_and_kernel_pca_tests/simple_nystrom_kernel_pca_test at test/ExtML/mlpack.jl:988 tests...
      Running ExtML mlpack tests/pca_and_kernel_pca_tests/simple_nystrom_kernel_pca_test at test/ExtML/mlpack.jl:988/simple_nystrom_kernel_pca_test at test/ExtML/mlpack.jl:988 tests...
    Running ExtML mlpack tests/pca_and_kernel_pca_tests/simple_epanechnikov_kernel_pca_test at test/ExtML/mlpack.jl:988 tests...
      Running ExtML mlpack tests/pca_and_kernel_pca_tests/simple_epanechnikov_kernel_pca_test at test/ExtML/mlpack.jl:988/simple_epanechnikov_kernel_pca_test at test/ExtML/mlpack.jl:988 tests...
    Running ExtML mlpack tests/pca_and_kernel_pca_tests/different_kernel_kernel_pca_test at test/ExtML/mlpack.jl:1047 tests...
      Running ExtML mlpack tests/pca_and_kernel_pca_tests/different_kernel_kernel_pca_test at test/ExtML/mlpack.jl:1047/different_kernel_kernel_pca_test at test/ExtML/mlpack.jl:1047 tests...
  Running ExtML mlpack tests/preprocess_split_test tests...
    Running ExtML mlpack tests/preprocess_split_test/simple_basic_preprocess_split_test at test/ExtML/mlpack.jl:1089 tests...
      Running ExtML mlpack tests/preprocess_split_test/simple_basic_preprocess_split_test at test/ExtML/mlpack.jl:1089/simple_basic_preprocess_split_test at test/ExtML/mlpack.jl:1089 tests...
input type: Array{Float64,2}
[WARN ] You did not specify `test_ratio`, so it will be automatically set to 0.2.
    Running ExtML mlpack tests/preprocess_split_test/simple_no_shuffle_preprocess_split_test at test/ExtML/mlpack.jl:1089 tests...
      Running ExtML mlpack tests/preprocess_split_test/simple_no_shuffle_preprocess_split_test at test/ExtML/mlpack.jl:1089/simple_no_shuffle_preprocess_split_test at test/ExtML/mlpack.jl:1089 tests...
input type: Array{Float64,2}
    Running ExtML mlpack tests/preprocess_split_test/simple_seed_preprocess_split_test at test/ExtML/mlpack.jl:1089 tests...
      Running ExtML mlpack tests/preprocess_split_test/simple_seed_preprocess_split_test at test/ExtML/mlpack.jl:1089/simple_seed_preprocess_split_test at test/ExtML/mlpack.jl:1089 tests...
input type: Array{Float64,2}
  Running ExtML mlpack tests/simple_nmf_tests tests...
    Running ExtML mlpack tests/simple_nmf_tests/simple_nmf_test at test/ExtML/mlpack.jl:1135 tests...
      Running ExtML mlpack tests/simple_nmf_tests/simple_nmf_test at test/ExtML/mlpack.jl:1135/simple_nmf_test at test/ExtML/mlpack.jl:1135 tests...
    Running ExtML mlpack tests/simple_nmf_tests/simple_nmf_multdiv_test at test/ExtML/mlpack.jl:1135 tests...
      Running ExtML mlpack tests/simple_nmf_tests/simple_nmf_multdiv_test at test/ExtML/mlpack.jl:1135/simple_nmf_multdiv_test at test/ExtML/mlpack.jl:1135 tests...
    Running ExtML mlpack tests/simple_nmf_tests/simple_nmf_als_test at test/ExtML/mlpack.jl:1135 tests...
      Running ExtML mlpack tests/simple_nmf_tests/simple_nmf_als_test at test/ExtML/mlpack.jl:1135/simple_nmf_als_test at test/ExtML/mlpack.jl:1135 tests...
  Running ExtML mlpack tests/simple_radical_tests tests...
    Running ExtML mlpack tests/simple_radical_tests/simple_radical_test at test/ExtML/mlpack.jl:1270 tests...
      Running ExtML mlpack tests/simple_radical_tests/simple_radical_test at test/ExtML/mlpack.jl:1270/simple_radical_test at test/ExtML/mlpack.jl:1270 tests...
    Running ExtML mlpack tests/simple_radical_tests/hyperparam_radical_test at test/ExtML/mlpack.jl:1270 tests...
      Running ExtML mlpack tests/simple_radical_tests/hyperparam_radical_test at test/ExtML/mlpack.jl:1270/hyperparam_radical_test at test/ExtML/mlpack.jl:1270 tests...
  Running ExtML mlpack tests/mlpack_parallel_tests tests...
    Running ExtML mlpack tests/mlpack_parallel_tests/test_delve_big_parallel_mlpack_query at test/ExtML/mlpack.jl:1358 tests...
      Running ExtML mlpack tests/mlpack_parallel_tests/test_delve_big_parallel_mlpack_query at test/ExtML/mlpack.jl:1358/test_delve_big_parallel_mlpack_query at test/ExtML/mlpack.jl:1358 tests...
simple_basic_preprocess_split_test at test/ExtML/mlpack.jl:1089: Error During Test at /home/ryan/work/relationalai/raicode2/src/Test/integration.jl:852
  Test threw exception
  Expression: begin
    result = API.Server.execute(txn; conversion = conversion)
    true
end
  DerivedFunctionException: Error encountered while executing derived function:
  UndefVarError: training not defined

  ------ Salsa Trace -----------------
...

In this example, I have printed the output

input type: Array{Float64,2}
[WARN ] You did not specify `test_ratio`, so it will be automatically set to 0.2.

from inside the test, in order to do some debugging, but the stacktrace associated with this test (that happens immediately after the [WARN ] output from mlpack) is much further down. This makes it harder to read the logs and figure out what is going on---is there a way to avoid scheduling all of the other tests until the currently running one is complete?

mdashti commented 3 years ago

Similarly: is there a way that I can choose to run only one test out of a test suite?

mdashti commented 3 years ago

@rcurtin That's already available via test filtering mechanism. Let's say, you see this test failed on Hydra: Delve/Integration/Basic/basic-ml/gdp-life-satisfaction-mse

Then you can run it via XUnit.runtests("test/runtests.jl", "Delve/Integration/Basic/basic-ml/gdp-life-satisfaction-mse").

Generally, you can call it via XUnit.runtests("test/runtests.jl", ["PATTERN1", "PATTERN2", ...])

Patterns are PCRE Regexes: https://www.debuggex.com/cheatsheet/regex/pcre

rcurtin commented 3 years ago

Thanks @mdashti for that tip! :+1: