Skip to content

Commit 8ca854a

Browse files
AetherUnboundlabkey-alan
authored andcommitted
Use pytest as default test runner, add test coverage (#24)
* Add more build artifacts to the gitignore * Update tests to use pytest as default runner, add coverage Also update the README and test dependencies * Produce HTML coverage report with terminal report
1 parent ea91ddf commit 8ca854a

11 files changed

+43
-54
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
*.py[cod]
33
build/
44
dist/
5+
\.coverage
6+
labkey\.egg-info/
7+
\.eggs/
58

69
# Project Artifacts
710
.idea/
8-
*.iml
11+
*.iml
12+
*.swp

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,21 @@ LabKey Server v15.1 and later.
106106
This package is maintained by [LabKey](http://www.labkey.com/). If you have any questions or need support, please use the [LabKey Server developer support forum](https://www.labkey.org/home/developer/forum/project-start.view).
107107

108108
### Testing
109-
If you are looking to contribute please run the tests before issuing a PR. For now you need to manually get the dependencies:
109+
If you are looking to contribute please run the tests before issuing a PR. The tests can be initiated by running
110110

111111
```bash
112-
$ pip install mock
112+
$ python setup.py test
113113
```
114114

115-
Then, to run the tests:
115+
This runs the tests using [pytest](https://docs.pytest.org/en/latest/contents.html). If you'd like to run pytest directly you can install the testing dependencies in your virtual environment with:
116116

117117
```bash
118-
$ python test/test_labkey.py
118+
$ pip install -e .[test]
119+
```
120+
121+
Then, the tests can be run with
122+
```bash
123+
$ pytest .
119124
```
120125

121126
### Maintainers

setup.cfg

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
[metadata]
2-
description-file = README.md
2+
description-file = README.md
3+
4+
[aliases]
5+
test=pytest
6+
7+
[tool:pytest]
8+
addopts = -v --cov=labkey --cov-config=setup.cfg --cov-report=html --cov-report=term
9+
10+
[coverage:html]
11+
directory = build/coverage_html
12+
title = Test coverage report for labkey

setup.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
long_desc = "Python client API for LabKey Server. Supports query and experiment APIs."
3838

39+
tests_require = ['pytest', 'requests', 'mock', 'pytest-cov']
40+
3941
setup(
4042
name='labkey',
4143
version=version,
@@ -50,7 +52,11 @@
5052
packages=packages,
5153
package_data={},
5254
install_requires=['requests'],
53-
tests_require=['requests', 'mock'],
55+
tests_require=tests_require,
56+
setup_requires=['pytest-runner'],
57+
extras_require={
58+
'test': tests_require
59+
},
5460
keywords="labkey api client",
5561
classifiers=[
5662
'Development Status :: 4 - Beta',

test/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from labkey import utils
2+
3+
# The mocks in the tests expect a request only to be made to the appropriate action.
4+
# This flag disables the CSRF check built into ServerContext.make_request() so the tests
5+
# get consistent results.
6+
utils.DISABLE_CSRF_CHECK = True

test/test_domain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from labkey.domain import create, Domain, drop, get, infer_fields, save
2929
from labkey.exceptions import RequestAuthorizationError
3030

31-
from utilities import MockLabKey, mock_server_context, success_test, success_test_get, throws_error_test, throws_error_test_get
31+
from .utilities import MockLabKey, mock_server_context, success_test, success_test_get, throws_error_test, throws_error_test_get
3232

3333

3434
domain_controller = 'property'

test/test_experiment_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from labkey.experiment import load_batch, save_batch, Batch, Run
2626
from labkey.exceptions import RequestError, QueryNotFoundError, ServerNotFoundError, RequestAuthorizationError
2727

28-
from utilities import MockLabKey, mock_server_context, success_test, throws_error_test
28+
from .utilities import MockLabKey, mock_server_context, success_test, throws_error_test
2929

3030

3131
class MockLoadBatch(MockLabKey):

test/test_labkey.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

test/test_query_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from labkey.query import delete_rows, update_rows, insert_rows, select_rows, execute_sql, QueryFilter
2626
from labkey.exceptions import RequestError, QueryNotFoundError, ServerNotFoundError, RequestAuthorizationError
2727

28-
from utilities import MockLabKey, mock_server_context, success_test, throws_error_test
28+
from .utilities import MockLabKey, mock_server_context, success_test, throws_error_test
2929

3030

3131
class MockSelectRows(MockLabKey):

test/test_security.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
remove_from_group, remove_from_role, add_to_role, get_roles, list_groups
2828
from labkey.exceptions import RequestError, QueryNotFoundError, ServerNotFoundError, RequestAuthorizationError
2929

30-
from utilities import MockLabKey, mock_server_context, success_test, throws_error_test
30+
from .utilities import MockLabKey, mock_server_context, success_test, throws_error_test
3131

3232

3333
class MockSecurityController(MockLabKey):

0 commit comments

Comments
 (0)