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

Use pytest for test running #297

Merged
merged 16 commits into from
Apr 28, 2022

Conversation

bryevdv
Copy link
Contributor

@bryevdv bryevdv commented Apr 21, 2022

This PR convert the existing test modules to use pytest for test discovery and running. Tests were also updated for minor cleanup and to utilize pytest features (e.g. parameterize and fixtures) effectively. The end result is to afford testing options that are more familiar and ergonomic to "standard" python devs.

Overview

Cleanup

A few commits perform some minor cleanup on the existing tests:

  • 572e7f1 — remove old and outdated "universal functions" tests
  • 5e0ff85 — remove a useless test
  • 5d8a617 — remove redundant bare return statements throughout

File movement

  • To make it easier to use pytest for test selection, the existing tests were moved and renamed:

  • 3f3c5cb — move files to integration subdirectory

  • 9f4f410 — prefix all test module filenames with test_

Moving the files to a subdirectory allows this entire group of tests to be easily run by executing pytest with this directory path. The test_ prefix is to conform with pytest expectations for default test discovery.

Pytest updates

  • 571ea07 — rename some helper functions to avoid test_ prefix. By default, pytest will interpret anything starting with test or Test as test to run.
  • 7677936 — a minimal update that adds pytest scaffolding to each test module and the least change to get running. For most tests this was just a couple of lines of boilerplate change. But a few tests required slightly more extensive updates.
  • bbda5a9 — more in-depth changed to split out tests into sensible smaller jobs, and to utilize parameterization and fixtures.

Notes

  • The existing test.py module runs exactly as before. The only change was to update it for the new path to the test files (see note about verbose output, though)
  • If desired to make this PR smaller, the final commit could be removed and submitted separately.
  • There is a legate.core issue that currently required fixtures to avoid cunumeric array re-use in tests
  • In the final commit I did try to split up tests and/or use parametrize anywhere it made sense, so that more fine-grained reporting output becomes available:
    tests/integration/test_reduction_complex.py::test_sum PASSED   [ 96%]
    tests/integration/test_reduction_complex.py::test_prod PASSED  [ 96%]
    tests/integration/test_repeat.py::test_basic PASSED            [ 96%]
    tests/integration/test_repeat.py::test_axis PASSED             [ 96%]
    tests/integration/test_repeat.py::test_nd[1] PASSED            [ 96%]
    tests/integration/test_repeat.py::test_nd[2] PASSED            [ 96%]
    tests/integration/test_repeat.py::test_nd[3] PASSED            [ 96%]
    tests/integration/test_repeat.py::test_nd[4] PASSED            [ 97%]
    

Further notes will be inline.

Operation

Running test.py

The existing way to run tests with test.py is unchanged:

./test.py --use=cuda 

This still generates the existing report:

image

(Note: Currently test.py -v only shows stdout from test.py and not from tests. This will be straightforward to restore but I would like to do that in a follow-on PR dedicated to test.py. Test stdout can be observed with either of the methods below with the standard -s flag. cc @magnatelee)

Executing individual tests

Individual tests can still be executed by running the module with legate including by passing in runtime command line options:

legate tests/integration/test_nonzero.py --gpus 2 -cunumeric:test

However, now the output is a standard pytest report:

image

It is also now possible to pass standard pytests options, e.g. -v for a verbose report:

image

Using pytest for test discovery

Although it is not yet possible to simply run pytest <dir> in the typical way, it is possible to achieve the same operation with a little more explicit invocation:

legate -c "import pytest; pytest.main(['tests/integration'])" --gpus 2 -cunumeric:test 

Note that all the standard pytest options, e.g. incluing -k and -m for test filtering, can be used.

The above will run all the tests under tests/integration, and generate a standard combined pytest report:

image

The full report output text can be seen here:

legate37 ❯ legate -c "import pytest; pytest.main(['tests/integration'])" --gpus 2 -cunumeric:test 

WARNING: Disabling control replication for interactive run
========================================================================================= test session starts ==========================================================================================
platform linux -- Python 3.7.12, pytest-7.1.1, pluggy-1.0.0
rootdir: /home/bryan/work/cunumeric
collected 2860 items                                                                                                                                                                                   

tests/integration/test_2d_reduction.py ...                                                                                                                                                       [  0%]
tests/integration/test_3d_reduction.py .                                                                                                                                                         [  0%]
tests/integration/test_advanced_indexing.py .                                                                                                                                                    [  0%]
tests/integration/test_append.py ........                                                                                                                                                        [  0%]
tests/integration/test_argmin.py ..                                                                                                                                                              [  0%]
tests/integration/test_array_creation.py ..............                                                                                                                                          [  1%]
tests/integration/test_array_split.py .......                                                                                                                                                    [  1%]
tests/integration/test_binary_op.py .....                                                                                                                                                        [  1%]
tests/integration/test_binary_op_2d.py ....                                                                                                                                                      [  1%]
tests/integration/test_binary_op_broadcast.py ....                                                                                                                                               [  1%]
tests/integration/test_binary_op_complex.py .....                                                                                                                                                [  1%]
tests/integration/test_binary_op_typing.py ..................................................................................................................................................... [  7%]
................................................................................................................................................................................................ [ 13%]
................................................................................................................................................................................................ [ 20%]
................................................................................................................................................................................................ [ 27%]
................................................................................................................................................................................................ [ 33%]
................................................................................................................................................................................................ [ 40%]
................................................................................................................................................................................................ [ 47%]
................................................................................................................................................................................................ [ 54%]
................................................................................................................................................................................................ [ 60%]
................................................................................................................................................................................................ [ 67%]
................................................................................................................................................................................................ [ 74%]
.................................................................................................................................................................................                [ 80%]
tests/integration/test_binary_ufunc.py .                                                                                                                                                         [ 80%]
tests/integration/test_bincount.py ......                                                                                                                                                        [ 80%]
tests/integration/test_block.py ............                                                                                                                                                     [ 81%]
tests/integration/test_cholesky.py .........                                                                                                                                                     [ 81%]
tests/integration/test_compare.py ......                                                                                                                                                         [ 81%]
tests/integration/test_complex_ops.py ....                                                                                                                                                       [ 81%]
tests/integration/test_concatenate_stack.py ................................................                                                                                                     [ 83%]
tests/integration/test_contains.py ..                                                                                                                                                            [ 83%]
tests/integration/test_convolve.py ......                                                                                                                                                        [ 83%]
tests/integration/test_copy.py .                                                                                                                                                                 [ 83%]
tests/integration/test_dot.py .........................                                                                                                                                          [ 84%]
tests/integration/test_einsum.py .......................................................................................................................................................         [ 89%]
tests/integration/test_eye.py ...............                                                                                                                                                    [ 90%]
tests/integration/test_fill.py .                                                                                                                                                                 [ 90%]
tests/integration/test_flatten.py .........                                                                                                                                                      [ 90%]
tests/integration/test_flip.py ..........                                                                                                                                                        [ 91%]
tests/integration/test_get_item.py .                                                                                                                                                             [ 91%]
tests/integration/test_index_routines.py ............                                                                                                                                            [ 91%]
tests/integration/test_ingest.py ....                                                                                                                                                            [ 91%]
tests/integration/test_inlinemap-keeps-region-alive.py .                                                                                                                                         [ 91%]
tests/integration/test_inner.py .........................                                                                                                                                        [ 92%]
tests/integration/test_interop.py .                                                                                                                                                              [ 92%]
tests/integration/test_intra_array_copy.py ....                                                                                                                                                  [ 92%]
tests/integration/test_jacobi.py .                                                                                                                                                               [ 92%]
tests/integration/test_length.py ....                                                                                                                                                            [ 92%]
tests/integration/test_linspace.py ....                                                                                                                                                          [ 93%]
tests/integration/test_logical.py .....s                                                                                                                                                         [ 93%]
tests/integration/test_lstm_backward_test.py .                                                                                                                                                   [ 93%]
tests/integration/test_lstm_simple_forward.py .                                                                                                                                                  [ 93%]
tests/integration/test_map_reduce.py .                                                                                                                                                           [ 93%]
tests/integration/test_mask.py ....                                                                                                                                                              [ 93%]
tests/integration/test_matmul.py ................                                                                                                                                                [ 94%]
tests/integration/test_nonzero.py ........                                                                                                                                                       [ 94%]
tests/integration/test_norm.py .                                                                                                                                                                 [ 94%]
tests/integration/test_numpy_interop.py .                                                                                                                                                        [ 94%]
tests/integration/test_outer.py .................                                                                                                                                                [ 95%]
tests/integration/test_overwrite_slice.py .                                                                                                                                                      [ 95%]
tests/integration/test_randint.py ..                                                                                                                                                             [ 95%]
tests/integration/test_reduction.py .......                                                                                                                                                      [ 95%]
tests/integration/test_reduction_axis.py ..................                                                                                                                                      [ 96%]
tests/integration/test_reduction_complex.py ..                                                                                                                                                   [ 96%]
tests/integration/test_repeat.py ......                                                                                                                                                          [ 96%]
tests/integration/test_reshape.py .................                                                                                                                                              [ 96%]
tests/integration/test_set_item.py .                                                                                                                                                             [ 96%]
tests/integration/test_shape.py .s                                                                                                                                                               [ 97%]
tests/integration/test_singleton_access.py .                                                                                                                                                     [ 97%]
tests/integration/test_slicing.py ..ss                                                                                                                                                           [ 97%]
tests/integration/test_sort.py .                                                                                                                                                                 [ 97%]
tests/integration/test_squeeze.py .                                                                                                                                                              [ 97%]
tests/integration/test_swapaxes.py ....                                                                                                                                                          [ 97%]
tests/integration/test_tensordot.py .........................                                                                                                                                    [ 98%]
tests/integration/test_tile.py ..                                                                                                                                                                [ 98%]
tests/integration/test_transpose.py ..                                                                                                                                                           [ 98%]
tests/integration/test_trilu.py ..........                                                                                                                                                       [ 98%]
tests/integration/test_unary_functions_2d.py ........                                                                                                                                            [ 99%]
tests/integration/test_unary_functions_2d_complex.py .....                                                                                                                                       [ 99%]
tests/integration/test_unary_ufunc.py .                                                                                                                                                          [ 99%]
tests/integration/test_unique.py .....                                                                                                                                                           [ 99%]
tests/integration/test_update.py .                                                                                                                                                               [ 99%]
tests/integration/test_vdot.py ....                                                                                                                                                              [ 99%]
tests/integration/test_view.py .                                                                                                                                                                 [ 99%]
tests/integration/test_vstack.py ...                                                                                                                                                             [ 99%]
tests/integration/test_where.py .....s                                                                                                                                                           [ 99%]
tests/integration/test_window.py .                                                                                                                                                               [100%]

=========================================================================================== warnings summary ===========================================================================================
tests/integration/test_advanced_indexing.py: 124 warnings
  /home/bryan/work/cunumeric/cunumeric/array.py:773: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    if key.dtype != np.bool and not np.issubdtype(

tests/integration/test_advanced_indexing.py: 124 warnings
  /home/bryan/work/cunumeric/cunumeric/array.py:777: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    if key.dtype != np.bool and key.dtype != np.int64:

tests/integration/test_advanced_indexing.py: 30 warnings
  /home/bryan/work/cunumeric/cunumeric/deferred.py:425: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    and key.dtype == np.bool

tests/integration/test_advanced_indexing.py: 120 warnings
  /home/bryan/work/cunumeric/cunumeric/deferred.py:479: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    and k.dtype == np.bool

tests/integration/test_advanced_indexing.py: 120 warnings
  /home/bryan/work/cunumeric/cunumeric/deferred.py:516: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    if k.dtype == np.bool:

tests/integration/test_advanced_indexing.py::test
  /home/bryan/work/cunumeric/tests/integration/test_advanced_indexing.py:118: RuntimeWarning: converting index array to int64 type
    assert np.array_equal(x[index], x_num[index_num])

tests/integration/test_advanced_indexing.py::test
  /home/bryan/work/cunumeric/tests/integration/test_advanced_indexing.py:122: RuntimeWarning: converting index array to int64 type
    x_num[index_num] = 3.5

tests/integration/test_advanced_indexing.py::test
  /home/bryan/work/cunumeric/tests/integration/test_advanced_indexing.py:129: UserWarning: cuNumeric performing implicit type conversion from float64 to int64
    x_num[index_num] = b_num

tests/integration/test_advanced_indexing.py::test
  /home/bryan/work/cunumeric/tests/integration/test_advanced_indexing.py:129: RuntimeWarning: converting index array to int64 type
    x_num[index_num] = b_num

tests/integration/test_advanced_indexing.py::test
  /home/bryan/work/cunumeric/tests/integration/test_advanced_indexing.py:559: UserWarning: cuNumeric performing implicit type conversion from float64 to int64
    z_num[indx_num] = b_num

tests/integration/test_advanced_indexing.py::test
  /home/bryan/work/cunumeric/tests/integration/test_advanced_indexing.py:609: RuntimeWarning: converting index array to int64 type
    res_num = x_num[ind_num, ind_num]

tests/integration/test_advanced_indexing.py::test
  /home/bryan/work/cunumeric/tests/integration/test_advanced_indexing.py:627: UserWarning: cuNumeric performing implicit type conversion from int16 to float64
    x_num[ind_num, ind_num] = b_num

tests/integration/test_cholesky.py::test_complex[8]
tests/integration/test_cholesky.py::test_complex[9]
tests/integration/test_cholesky.py::test_complex[255]
tests/integration/test_cholesky.py::test_complex[512]
  /home/bryan/work/cunumeric/tests/integration/test_cholesky.py:48: UserWarning: cuNumeric performing implicit type conversion from complex128 to float64
    d[1] = b

tests/integration/test_dot.py::test_dot[1-1]
tests/integration/test_dot.py::test_dot[1-2]
tests/integration/test_dot.py::test_dot[2-1]
tests/integration/test_dot.py::test_dot[2-2]
  /home/bryan/work/cunumeric/tests/integration/test_dot.py:34: UserWarning: cuNumeric performing implicit type conversion from float16 to float32
    return lib.dot(*args, **kwargs)

tests/integration/test_einsum.py::test_cast[->]
tests/integration/test_einsum.py::test_cast[a->]
tests/integration/test_einsum.py::test_cast[a,->]
tests/integration/test_einsum.py::test_cast[a,a->]
  /home/bryan/work/cunumeric/cunumeric/array.py:123: ComplexWarning: Casting complex values to real discards the imaginary part
    *args, **kwargs

tests/integration/test_einsum.py::test_cast[a->a]
tests/integration/test_einsum.py::test_cast[a,->a]
tests/integration/test_einsum.py::test_cast[a,a->]
tests/integration/test_einsum.py::test_cast[a,a->a]
tests/integration/test_einsum.py::test_cast[a,b->ab]
tests/integration/test_einsum.py::test_cast[ab,ca->a]
tests/integration/test_einsum.py::test_cast[ab,ca->b]
  /home/bryan/work/cunumeric/tests/integration/test_einsum.py:235: UserWarning: cuNumeric performing implicit type conversion from float16 to float32
    cn.einsum(expr, *cn_inputs, out=cn_out)

tests/integration/test_einsum.py::test_cast[a->a]
tests/integration/test_einsum.py::test_cast[a,->a]
tests/integration/test_einsum.py::test_cast[a,a->]
tests/integration/test_einsum.py::test_cast[a,a->a]
tests/integration/test_einsum.py::test_cast[a,b->ab]
tests/integration/test_einsum.py::test_cast[ab,ca->a]
tests/integration/test_einsum.py::test_cast[ab,ca->b]
  /home/bryan/work/cunumeric/tests/integration/test_einsum.py:235: UserWarning: cuNumeric performing implicit type conversion from float16 to complex64
    cn.einsum(expr, *cn_inputs, out=cn_out)

tests/integration/test_einsum.py::test_cast[a->a]
tests/integration/test_einsum.py::test_cast[a,->a]
tests/integration/test_einsum.py::test_cast[a,a->a]
tests/integration/test_einsum.py::test_cast[a,b->ab]
tests/integration/test_einsum.py::test_cast[ab,ca->a]
tests/integration/test_einsum.py::test_cast[ab,ca->b]
  /home/bryan/work/cunumeric/tests/integration/test_einsum.py:235: UserWarning: cuNumeric performing implicit type conversion from float32 to float16
    cn.einsum(expr, *cn_inputs, out=cn_out)

tests/integration/test_einsum.py::test_cast[a->a]
tests/integration/test_einsum.py::test_cast[a,->a]
tests/integration/test_einsum.py::test_cast[a,a->]
tests/integration/test_einsum.py::test_cast[a,a->a]
tests/integration/test_einsum.py::test_cast[a,b->ab]
tests/integration/test_einsum.py::test_cast[ab,ca->a]
tests/integration/test_einsum.py::test_cast[ab,ca->b]
  /home/bryan/work/cunumeric/tests/integration/test_einsum.py:235: UserWarning: cuNumeric performing implicit type conversion from float32 to complex64
    cn.einsum(expr, *cn_inputs, out=cn_out)

tests/integration/test_einsum.py::test_cast[a->a]
tests/integration/test_einsum.py::test_cast[a,->a]
tests/integration/test_einsum.py::test_cast[a,a->a]
tests/integration/test_einsum.py::test_cast[a,b->ab]
tests/integration/test_einsum.py::test_cast[ab,ca->a]
tests/integration/test_einsum.py::test_cast[ab,ca->b]
  /home/bryan/work/cunumeric/tests/integration/test_einsum.py:235: UserWarning: cuNumeric performing implicit type conversion from complex64 to float16
    cn.einsum(expr, *cn_inputs, out=cn_out)

tests/integration/test_einsum.py::test_cast[a->a]
tests/integration/test_einsum.py::test_cast[a,->a]
tests/integration/test_einsum.py::test_cast[a,a->a]
tests/integration/test_einsum.py::test_cast[a,b->ab]
tests/integration/test_einsum.py::test_cast[ab,ca->a]
tests/integration/test_einsum.py::test_cast[ab,ca->b]
  /home/bryan/work/cunumeric/tests/integration/test_einsum.py:235: UserWarning: cuNumeric performing implicit type conversion from complex64 to float32
    cn.einsum(expr, *cn_inputs, out=cn_out)

tests/integration/test_einsum.py::test_cast[a,a->]
tests/integration/test_einsum.py::test_cast[a,a->a]
tests/integration/test_einsum.py::test_cast[a,b->ab]
tests/integration/test_einsum.py::test_cast[ab,ca->a]
tests/integration/test_einsum.py::test_cast[ab,ca->b]
  /home/bryan/work/cunumeric/tests/integration/test_einsum.py:228: UserWarning: cuNumeric performing implicit type conversion from float16 to float32
    cn_res = cn.einsum(expr, *cn_inputs)

tests/integration/test_einsum.py::test_cast[a,a->]
tests/integration/test_einsum.py::test_cast[a,a->a]
tests/integration/test_einsum.py::test_cast[a,b->ab]
tests/integration/test_einsum.py::test_cast[ab,ca->a]
tests/integration/test_einsum.py::test_cast[ab,ca->b]
  /home/bryan/work/cunumeric/tests/integration/test_einsum.py:228: UserWarning: cuNumeric performing implicit type conversion from float16 to complex64
    cn_res = cn.einsum(expr, *cn_inputs)

tests/integration/test_einsum.py::test_cast[a,a->]
tests/integration/test_einsum.py::test_cast[a,a->a]
tests/integration/test_einsum.py::test_cast[a,b->ab]
tests/integration/test_einsum.py::test_cast[ab,ca->a]
tests/integration/test_einsum.py::test_cast[ab,ca->b]
  /home/bryan/work/cunumeric/tests/integration/test_einsum.py:228: UserWarning: cuNumeric performing implicit type conversion from float32 to complex64
    cn_res = cn.einsum(expr, *cn_inputs)

tests/integration/test_flatten.py::test_basic[(1, 1)]
tests/integration/test_flatten.py::test_basic[(1, 1, 1)]
tests/integration/test_flatten.py::test_basic[(1, 10)]
tests/integration/test_flatten.py::test_basic[(1, 10, 1)]
tests/integration/test_flatten.py::test_basic[(10, 10)]
tests/integration/test_flatten.py::test_basic[(10, 10, 10)]
  /home/bryan/work/cunumeric/tests/integration/test_flatten.py:26: RuntimeWarning: cuNumeric has not implemented reshape using Fortran-like index order and is falling back to canonical numpy. You may notice significantly decreased performance for this function call.
    c = num_arr.flatten(order)

tests/integration/test_index_routines.py::test_choose_1d
  /home/bryan/work/cunumeric/tests/integration/test_index_routines.py:42: UserWarning: cuNumeric performing implicit type conversion from int64 to float64
    assert np.array_equal(

tests/integration/test_sort.py::test
  /home/bryan/work/cunumeric/tests/integration/test_sort.py:23: UserWarning: cuNumeric performing implicit type conversion from complex64 to complex128
    if not num.allclose(a_np, a_num):

tests/integration/test_vdot.py::test[complex64-complex128]
tests/integration/test_vdot.py::test[complex128-complex64]
  /home/bryan/work/cunumeric/tests/integration/test_vdot.py:28: UserWarning: cuNumeric performing implicit type conversion from complex64 to complex128
    mk_0to1_array(lib, (5,), dtype=b_dtype),

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================================================ 2855 passed, 5 skipped, 601 warnings in 41.34s ============================================================================

There are some warning that show up in the output at the end, mostly about implicit casting. I am not sure if these are expected or not (I expect they would be)

Future work

Things that are not in this PR but are planned for follow-on PRs:

  • Using pytest to run the examples
  • Restoring previous -v behaviour to test.py
  • Increased documentation for running tests
  • Allowing to run with simpler legate -m pytest

@bryevdv
Copy link
Contributor Author

bryevdv commented Apr 21, 2022

I should note also: the advanced indexing PR was merged while I was still working on this. There was a small conflict for a few tests but I believe everything is carried over as it should be. But more eyes especially on that would be advised.

@bryevdv
Copy link
Contributor Author

bryevdv commented Apr 22, 2022

@magnatelee @manopapad For now I am going to fix conflicts as they arise with rebase / force-push to keep the commit history clean. Let me know when you are starting a review and I will switch to merges if needed

@bryevdv
Copy link
Contributor Author

bryevdv commented Apr 26, 2022

moved/renamed/updated the recently merged fft tests in 4b81936 @mferreravila please take a look at the changes cc @magnatelee

tests/integration/test_binary_op.py Outdated Show resolved Hide resolved
tests/integration/test_binary_op_2d.py Outdated Show resolved Hide resolved
tests/integration/test_binary_op_typing.py Outdated Show resolved Hide resolved
tests/integration/test_compare.py Outdated Show resolved Hide resolved
tests/integration/test_fft_c2c.py Show resolved Hide resolved
tests/integration/test_map_reduce.py Show resolved Hide resolved
tests/integration/test_reduction_complex.py Show resolved Hide resolved
tests/integration/test_shape.py Outdated Show resolved Hide resolved
tests/integration/test_unary_functions_2d.py Outdated Show resolved Hide resolved
@magnatelee
Copy link
Contributor

@bryevdv I left some comments. Looks good to me otherwise.

One thing I noticed though is that the pytest driver seems to be hiding standard error messages that only show up with the -s flag. This isn't a problem per se, but we should inform the developers that any runtime error messages may not show up until the flag is passed. Even better would be to somehow pass -s to the tests by default, but I don't know whether that's even possible.

@bryevdv
Copy link
Contributor Author

bryevdv commented Apr 27, 2022

@mferreravila 👍 For now I left all the print statements, but I parameterized them and moved to the "check" helper function, which is more convenient with parameterized tests in pytest

@bryevdv
Copy link
Contributor Author

bryevdv commented Apr 27, 2022

@magnatelee see #297 (comment) for some comments. There's definitely lots of options. E.g. a test wrapper (like test.py) could always supply -s by default, leaving "manual" pytest usage completely configurable. I think personally I would advise trying to make -v output sufficient for most normal usage, and leave -s only for times when detailed tracing is necessary.

@bryevdv
Copy link
Contributor Author

bryevdv commented Apr 27, 2022

One thing I noticed though is that the pytest driver seems to be hiding standard error messages that only show up with the -s flag. This isn't a problem per se, but we should inform the developers that any runtime error messages may not show up until the flag is passed.

@magnatelee actually I may not have fully appreciated this comment. Are you saying that there can be runtime error messages with tests still passing? If a runtime error causes a test to fail (or fail to run) then it should be captured and displayed at the end of the pytest report with or without -s

Or, do you mean when running with test.py -v? If so, then that is known (and I will fix in a follow-up PR) Apologies this note was buried in the OP:

(Note: Currently test.py -v only shows stdout from test.py and not from tests [themselves]. This will be straightforward to restore but I would like to do that in a follow-on PR dedicated to test.py. Test stdout can be observed with either of the methods below with the standard -s flag. cc @magnatelee)

@bryevdv
Copy link
Contributor Author

bryevdv commented Apr 27, 2022

@magnatelee here is an extremely quick and dirty diff that restores stdout from tests when test.py -v is used:

diff --git a/test.py b/test.py
index 00f64c1..75239a3 100755
--- a/test.py
+++ b/test.py
@@ -108,6 +108,8 @@ def run_test(
     only_pattern,
 ):
     test_path = os.path.join(root_dir, test_file)
+    if "integration" in test_path and verbose:
+        opts = opts + ["-s"]
     try:
         cmd(
             [driver, test_path] + flags + test_flags + opts,

Would you like me to include it in this PR for now? I'd plan to fix it better in a PR dedicated to test.py

Edit: could also consider opts = opts + ["-v", "-s"] if that is preferable

@magnatelee
Copy link
Contributor

@bryevdv I wasn't talking about test.py, for which we could do whatever we want. I was talking about the case where I run individual tests manually.

If a runtime error causes a test to fail (or fail to run) then it should be captured and displayed at the end of the pytest report with or without -s

This doesn't seem to be true. The pytest report only printed out any error messages from Python and masked those from the C++ runtime. I was able to see them only when I passed -s manually.

Edit: could also consider opts = opts + ["-v", "-s"] if that is preferable

Yes, I think we need both -v and -s for pytest when -v is passed to test.py.

@bryevdv
Copy link
Contributor Author

bryevdv commented Apr 28, 2022

@mfoerste4 please confirm the merge conflict resolution in daa5ef9

@bryevdv
Copy link
Contributor Author

bryevdv commented Apr 28, 2022

Noting that 44771ea sets the default pytest capture mode to "sys" for our repo, in order to correctly display stack traces in case of cpp runtime errors. It is still unclear why the default mode "fd" gets confused and prevents those from being reported, but this should be a low-risk change to move forward in the immediate term.

@mfoerste4
Copy link
Contributor

@mfoerste4 please confirm the merge conflict resolution in daa5ef9

LGTM

@bryevdv bryevdv merged commit 43d3fd4 into nv-legate:branch-22.05 Apr 28, 2022
@bryevdv bryevdv deleted the bryanv/pytest_integration branch April 28, 2022 20:28
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.

4 participants