Skip to content

Conversation

AetherUnbound
Copy link
Contributor

@AetherUnbound AetherUnbound commented Apr 6, 2019

Change context

I've noticed that the README's instructions for running the unit tests has a custom test runner and requires installing the test dependencies explicitly. We've used pytest in the past with great success, so I thought I'd apply it here.

This changeset

This PR changes the default test runner to be pytest, and separates the test dependencies out into a separate extras group that can be installed with the .[<group>] syntax (e.g. pip install -e .[test]). The tests can either be run with pytest . or python setup.py test. Additionally, the tests also produce a coverage report available under build/coverage_html.

Example output of testing:

=============================================== test session starts ===============================================
platform linux -- Python 3.7.1, pytest-4.4.0, py-1.8.0, pluggy-0.9.0 -- /home/aether/programs/anaconda3/envs/labkey-api-python/bin/python
cachedir: .pytest_cache
rootdir: /home/aether/git/labkey-api-python, inifile: setup.cfg
plugins: cov-2.6.1
collected 103 items                                                                                               

test/test_domain.py::TestCreate::test_success PASSED                                                        [  0%]
test/test_domain.py::TestCreate::test_unauthorized PASSED                                                   [  1%]
test/test_domain.py::TestDrop::test_success PASSED                                                          [  2%]
test/test_domain.py::TestDrop::test_unauthorized PASSED                                                     [  3%]
test/test_domain.py::TestGet::test_success PASSED                                                           [  4%]
test/test_domain.py::TestGet::test_unauthorized PASSED                                                      [  5%]
test/test_domain.py::TestInferFields::test_success PASSED                                                   [  6%]
test/test_domain.py::TestInferFields::test_unauthorized PASSED                                              [  7%]
test/test_domain.py::TestSave::test_success PASSED                                                          [  8%]
test/test_domain.py::TestSave::test_unauthorized PASSED                                                     [  9%]
test/test_experiment_api.py::TestLoadBatch::test_general_error PASSED                                       [ 10%]
test/test_experiment_api.py::TestLoadBatch::test_query_not_found PASSED                                     [ 11%]
test/test_experiment_api.py::TestLoadBatch::test_server_not_found PASSED                                    [ 12%]
test/test_experiment_api.py::TestLoadBatch::test_success PASSED                                             [ 13%]
test/test_experiment_api.py::TestLoadBatch::test_unauthorized PASSED                                        [ 14%]
test/test_experiment_api.py::TestSaveBatch::test_general_error PASSED                                       [ 15%]
test/test_experiment_api.py::TestSaveBatch::test_query_not_found PASSED                                     [ 16%]
test/test_experiment_api.py::TestSaveBatch::test_server_not_found PASSED                                    [ 17%]
test/test_experiment_api.py::TestSaveBatch::test_success PASSED                                             [ 18%]
test/test_experiment_api.py::TestSaveBatch::test_unauthorized PASSED                                        [ 19%]
test/test_query_api.py::TestDeleteRows::test_general_error PASSED                                           [ 20%]
test/test_query_api.py::TestDeleteRows::test_query_not_found PASSED                                         [ 21%]
test/test_query_api.py::TestDeleteRows::test_server_not_found PASSED                                        [ 22%]
test/test_query_api.py::TestDeleteRows::test_success PASSED                                                 [ 23%]
test/test_query_api.py::TestDeleteRows::test_unauthorized PASSED                                            [ 24%]
test/test_query_api.py::TestUpdateRows::test_general_error PASSED                                           [ 25%]
test/test_query_api.py::TestUpdateRows::test_query_not_found PASSED                                         [ 26%]
test/test_query_api.py::TestUpdateRows::test_server_not_found PASSED                                        [ 27%]
test/test_query_api.py::TestUpdateRows::test_success PASSED                                                 [ 28%]
test/test_query_api.py::TestUpdateRows::test_unauthorized PASSED                                            [ 29%]
test/test_query_api.py::TestInsertRows::test_general_error PASSED                                           [ 30%]
test/test_query_api.py::TestInsertRows::test_query_not_found PASSED                                         [ 31%]
test/test_query_api.py::TestInsertRows::test_server_not_found PASSED                                        [ 32%]
test/test_query_api.py::TestInsertRows::test_success PASSED                                                 [ 33%]
test/test_query_api.py::TestInsertRows::test_unauthorized PASSED                                            [ 33%]
test/test_query_api.py::TestExecuteSQL::test_general_error PASSED                                           [ 34%]
test/test_query_api.py::TestExecuteSQL::test_query_not_found PASSED                                         [ 35%]
test/test_query_api.py::TestExecuteSQL::test_server_not_found PASSED                                        [ 36%]
test/test_query_api.py::TestExecuteSQL::test_success PASSED                                                 [ 37%]
test/test_query_api.py::TestExecuteSQL::test_unauthorized PASSED                                            [ 38%]
test/test_query_api.py::TestSelectRows::test_general_error PASSED                                           [ 39%]
test/test_query_api.py::TestSelectRows::test_query_not_found PASSED                                         [ 40%]
test/test_query_api.py::TestSelectRows::test_server_not_found PASSED                                        [ 41%]
test/test_query_api.py::TestSelectRows::test_success PASSED                                                 [ 42%]
test/test_query_api.py::TestSelectRows::test_unauthorized PASSED                                            [ 43%]
test/test_security.py::TestCreateUser::test_general_error PASSED                                            [ 44%]
test/test_security.py::TestCreateUser::test_query_not_found PASSED                                          [ 45%]
test/test_security.py::TestCreateUser::test_server_not_found PASSED                                         [ 46%]
test/test_security.py::TestCreateUser::test_success PASSED                                                  [ 47%]
test/test_security.py::TestCreateUser::test_unauthorized PASSED                                             [ 48%]
test/test_security.py::TestResetPassword::test_general_error PASSED                                         [ 49%]
test/test_security.py::TestResetPassword::test_query_not_found PASSED                                       [ 50%]
test/test_security.py::TestResetPassword::test_server_not_found PASSED                                      [ 51%]
test/test_security.py::TestResetPassword::test_success PASSED                                               [ 52%]
test/test_security.py::TestResetPassword::test_unauthorized PASSED                                          [ 53%]
test/test_security.py::TestActivateUsers::test_general_error PASSED                                         [ 54%]
test/test_security.py::TestActivateUsers::test_query_not_found PASSED                                       [ 55%]
test/test_security.py::TestActivateUsers::test_server_not_found PASSED                                      [ 56%]
test/test_security.py::TestActivateUsers::test_success PASSED                                               [ 57%]
test/test_security.py::TestActivateUsers::test_unauthorized PASSED                                          [ 58%]
test/test_security.py::TestDeactivateUsers::test_general_error PASSED                                       [ 59%]
test/test_security.py::TestDeactivateUsers::test_query_not_found PASSED                                     [ 60%]
test/test_security.py::TestDeactivateUsers::test_server_not_found PASSED                                    [ 61%]
test/test_security.py::TestDeactivateUsers::test_success PASSED                                             [ 62%]
test/test_security.py::TestDeactivateUsers::test_unauthorized PASSED                                        [ 63%]
test/test_security.py::TestDeleteUsers::test_general_error PASSED                                           [ 64%]
test/test_security.py::TestDeleteUsers::test_query_not_found PASSED                                         [ 65%]
test/test_security.py::TestDeleteUsers::test_server_not_found PASSED                                        [ 66%]
test/test_security.py::TestDeleteUsers::test_success PASSED                                                 [ 66%]
test/test_security.py::TestDeleteUsers::test_unauthorized PASSED                                            [ 67%]
test/test_security.py::TestAddToGroup::test_general_error PASSED                                            [ 68%]
test/test_security.py::TestAddToGroup::test_query_not_found PASSED                                          [ 69%]
test/test_security.py::TestAddToGroup::test_server_not_found PASSED                                         [ 70%]
test/test_security.py::TestAddToGroup::test_success PASSED                                                  [ 71%]
test/test_security.py::TestAddToGroup::test_unauthorized PASSED                                             [ 72%]
test/test_security.py::TestRemoveFromGroup::test_general_error PASSED                                       [ 73%]
test/test_security.py::TestRemoveFromGroup::test_query_not_found PASSED                                     [ 74%]
test/test_security.py::TestRemoveFromGroup::test_server_not_found PASSED                                    [ 75%]
test/test_security.py::TestRemoveFromGroup::test_success PASSED                                             [ 76%]
test/test_security.py::TestRemoveFromGroup::test_unauthorized PASSED                                        [ 77%]
test/test_security.py::TestRemoveFromRole::test_general_error PASSED                                        [ 78%]
test/test_security.py::TestRemoveFromRole::test_query_not_found PASSED                                      [ 79%]
test/test_security.py::TestRemoveFromRole::test_server_not_found PASSED                                     [ 80%]
test/test_security.py::TestRemoveFromRole::test_success PASSED                                              [ 81%]
test/test_security.py::TestRemoveFromRole::test_unauthorized PASSED                                         [ 82%]
test/test_security.py::TestAddToRole::test_general_error PASSED                                             [ 83%]
test/test_security.py::TestAddToRole::test_query_not_found PASSED                                           [ 84%]
test/test_security.py::TestAddToRole::test_server_not_found PASSED                                          [ 85%]
test/test_security.py::TestAddToRole::test_success PASSED                                                   [ 86%]
test/test_security.py::TestAddToRole::test_unauthorized PASSED                                              [ 87%]
test/test_security.py::TestGetRoles::test_general_error PASSED                                              [ 88%]
test/test_security.py::TestGetRoles::test_query_not_found PASSED                                            [ 89%]
test/test_security.py::TestGetRoles::test_server_not_found PASSED                                           [ 90%]
test/test_security.py::TestGetRoles::test_success PASSED                                                    [ 91%]
test/test_security.py::TestGetRoles::test_unauthorized PASSED                                               [ 92%]
test/test_security.py::TestListGroups::test_general_error PASSED                                            [ 93%]
test/test_security.py::TestListGroups::test_query_not_found PASSED                                          [ 94%]
test/test_security.py::TestListGroups::test_server_not_found PASSED                                         [ 95%]
test/test_security.py::TestListGroups::test_success PASSED                                                  [ 96%]
test/test_security.py::TestListGroups::test_unauthorized PASSED                                             [ 97%]
test/test_unsupported.py::TestPostMessage::test_success PASSED                                              [ 98%]
test/test_utils.py::TestJsonDumps::test_encoder PASSED                                                      [ 99%]
test/test_utils.py::TestJsonDumps::test_encoder_override PASSED                                             [100%]

----------- coverage: platform linux, python 3.7.1-final-0 -----------
Name                                 Stmts   Miss  Cover
--------------------------------------------------------
labkey/__init__.py                       5      0   100%
labkey/domain.py                       198    109    45%
labkey/exceptions.py                    33      3    91%
labkey/experiment.py                   130     32    75%
labkey/query.py                        124     32    74%
labkey/security.py                      59     12    80%
labkey/unsupported/__init__.py           0      0   100%
labkey/unsupported/messageboard.py      13      4    69%
labkey/unsupported/wiki.py              42     42     0%
labkey/utils.py                         97     19    80%
--------------------------------------------------------
TOTAL                                  701    253    64%
Coverage HTML written to dir build/coverage_html


=========================================== 103 passed in 0.51 seconds ============================================

@labkey-alan labkey-alan merged commit 8ca854a into LabKey:master May 2, 2019
@AetherUnbound AetherUnbound deleted the feature/pytest branch May 3, 2019 00:14
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.

2 participants