Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
cc8c254e
Commit
cc8c254e
authored
5 months ago
by
Florian Spreckelsen
Browse files
Options
Downloads
Patches
Plain Diff
DOC: Fix and extend docstrings of linkahead.utils.register_tests
parent
0dbb1a19
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!189
ENH: add convenience functions
,
!176
F doc test registration
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/linkahead/utils/register_tests.py
+47
-25
47 additions, 25 deletions
src/linkahead/utils/register_tests.py
with
47 additions
and
25 deletions
src/linkahead/utils/register_tests.py
+
47
−
25
View file @
cc8c254e
...
@@ -18,44 +18,62 @@
...
@@ -18,44 +18,62 @@
#
#
# You should have received a copy of the GNU Affero General Public License
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
This module implements a registration procedure for integration tests which
import
linkahead
as
db
from
linkahead
import
administration
as
admin
"""
This module implements a registration procedure for integration tests which
need a running LinkAhead instance.
need a running LinkAhead instance.
It ensures that tests do not accidentally overwrite data in real LinkAhead
It ensures that tests do not accidentally overwrite data in real
instances, as it checks whether the running LinkAhead instance is actually the
LinkAhead instances, as it checks whether the running LinkAhead
correct one, that
instance is actually the correct one, that should be used for these
should be used for these tests.
tests.
The test files have to define a global variable TEST_KEY which must be unique
for each test using
set_test_key(
"
ABCDE
"
)
The test files have to define a global variable ``TEST_KEY`` which
must be unique for each test using
:py:meth:`~linkahead.utils.register_tests.set_test_key`.
The test procedure (invoked by pytest) checks whether a registration
The test procedure (invoked by pytest) checks whether a registration
information is stored in one of the server properties or otherwise
information is stored in one of the server properties or otherwise
- offers to register this test in the currently running database ONLY if this
is empty.
- offers to register this test in the currently running database ONLY if this is
empty.
- fails otherwise with a RuntimeError
- fails otherwise with a RuntimeError
NOTE: you probably need to use pytest with the -s option to be able to
.. note::
register the test interactively. Otherwise, the server property has to be
set before server start-up in the server.conf of the LinkAhead server.
you probably need to use pytest with the -s option to be able to
register the test interactively. Otherwise, the server property
has to be set before server start-up in the server.conf of the
LinkAhead server.
This module is intended to be used with pytest.
This module is intended to be used with pytest.
There is a pytest fixture
"
clear_database
"
that performs the above mentioned
There is a pytest fixture
checks and clears the database in case of success.
:py:meth:`~linkahead.utils.register_tests.clear_database` that
performs the above mentioned checks and clears the database in case of
success.
"""
"""
import
linkahead
as
db
from
linkahead
import
administration
as
admin
TEST_KEY
=
None
TEST_KEY
=
None
def
set_test_key
(
KEY
):
def
set_test_key
(
KEY
:
str
):
"""
Set the global ``TEST_KEY`` variable to `KEY`. Afterwards, if
`KEY` matches the ``_CAOSDB_INTEGRATION_TEST_SUITE_KEY`` server
environment variable, mehtods like :py:meth:`clear_database` can
be used. Call this function in the beginning of your test file.
Parameters
----------
KEY : str
key with which the test using this function is registered and
which is checked against the
``_CAOSDB_INTEGRATION_TEST_SUITE_KEY`` server environment
variable.
"""
global
TEST_KEY
global
TEST_KEY
TEST_KEY
=
KEY
TEST_KEY
=
KEY
...
@@ -122,10 +140,14 @@ try:
...
@@ -122,10 +140,14 @@ try:
@pytest.fixture
@pytest.fixture
def
clear_database
():
def
clear_database
():
"""
Remove Records, RecordTypes, Properties, and Files ONLY IF the LinkAhead
"""
Remove Records, RecordTypes, Properties, and Files ONLY IF
server the current connection points to was registered with the appropriate key.
the LinkAhead server the current connection points to was
registered with the appropriate key using
:py:meth:`set_test_key`.
PyTestInfo Records and the corresponding RecordType and
Property are preserved.
PyTestInfo Records and the corresponding RecordType and Property are preserved.
"""
"""
_assure_test_is_registered
()
_assure_test_is_registered
()
yield
_clear_database
()
# called before the test function
yield
_clear_database
()
# called before the test function
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment