Coverage for tools/run_server_self_tests.py: 56%
16 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
1#!/usr/bin/env python
3"""
4camcops_server/tools/run_server_self_tests.py
6===============================================================================
8 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
9 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
11 This file is part of CamCOPS.
13 CamCOPS is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
18 CamCOPS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
26===============================================================================
28**Run server self-tests.**
30"""
32import os
33import subprocess
34import sys
36from cardinal_pythonlib.cmdline import cmdline_quote
38from camcops_server.cc_modules.cc_baseconstants import CAMCOPS_SERVER_DIRECTORY
39from camcops_server.conftest import TEST_DATABASE_FILENAME
42def main() -> None:
43 cmdargs = ["pytest"] + sys.argv[1:]
44 formatted_args = cmdline_quote(cmdargs)
45 print(
46 f"""
47- You can run tests manually via one of these methods:
48 pytest # all tests
49 pytest FILE.py # one test file
50 pytest FILE.py::some_function # one test function
51 pytest FILE.py::SomeClass # one test class
52 pytest FILE.py::SomeClass::some_member_function # function within class
53 pytest -k search_term # all matching test files, functions, classes, etc.
55- Pytest will find additional options in:
56 {CAMCOPS_SERVER_DIRECTORY}/conftest.py
57 {CAMCOPS_SERVER_DIRECTORY}/pytest.ini
58 ... if you are running pytest manually, RUN FROM THAT DIRECTORY.
60- Note that an SQLite database is saved in
61 {TEST_DATABASE_FILENAME}
62 ... DELETE THAT AND RETRY IF THE TESTS FAIL!
64- We'll do this now:
65 cd {CAMCOPS_SERVER_DIRECTORY}
66 {formatted_args}
67"""
68 )
69 # https://stackoverflow.com/questions/36456920
70 # examples:
71 # pytest client_api_tests.py::ClientApiTests::test_client_api_validators
72 # pytest webview_tests.py::WebviewTests::test_webview_constant_validators
73 # pytest cc_validator_tests.py
75 # print(f"cmdargs: {cmdargs!r}")
76 input("Press Enter when ready...")
77 os.chdir(CAMCOPS_SERVER_DIRECTORY)
78 subprocess.run(cmdargs)
81if __name__ == "__main__":
82 main()