Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
Workers
Base Worker
Commits
99504a12
Commit
99504a12
authored
4 years ago
by
Bastien Abadie
Browse files
Options
Downloads
Patches
Plain Diff
Cache YAML payloads in tests
parent
6fc5b19f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!59
Cache YAML payloads in tests
Pipeline
#78247
passed
4 years ago
Stage: release
Changes
1
Pipelines
4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/conftest.py
+31
-1
31 additions, 1 deletion
tests/conftest.py
with
31 additions
and
1 deletion
tests/conftest.py
+
31
−
1
View file @
99504a12
# -*- coding: utf-8 -*-
import
hashlib
import
json
import
os
import
sys
from
pathlib
import
Path
import
pytest
import
yaml
from
arkindex.mock
import
MockApiClient
from
arkindex_worker.git
import
GitHelper
,
GitlabHelper
...
...
@@ -12,9 +14,37 @@ from arkindex_worker.worker import ElementsWorker
FIXTURES_DIR
=
Path
(
__file__
).
resolve
().
parent
/
"
data
"
__yaml_cache
=
{}
@pytest.fixture
def
cache_yaml
(
monkeypatch
):
"""
Cache all calls to yaml.safe_load in order to speedup
every test cases that load the OpenAPI schema
"""
# Keep a reference towards the original function
_original_yaml_load
=
yaml
.
safe_load
def
_cached_yaml_load
(
yaml_payload
):
# Create a unique cache key for direct YAML strings
# and file descriptors
if
isinstance
(
yaml_payload
,
str
):
key
=
hashlib
.
md5
(
yaml_payload
.
encode
(
"
utf-8
"
)).
hexdigest
()
else
:
key
=
yaml_payload
.
name
# Cache result
if
key
not
in
__yaml_cache
:
__yaml_cache
[
key
]
=
_original_yaml_load
(
yaml_payload
)
return
__yaml_cache
[
key
]
monkeypatch
.
setattr
(
yaml
,
"
safe_load
"
,
_cached_yaml_load
)
@pytest.fixture
(
autouse
=
True
)
def
setup_api
(
responses
,
monkeypatch
):
def
setup_api
(
responses
,
monkeypatch
,
cache_yaml
):
# Always use the environment variable first
schema_url
=
os
.
environ
.
get
(
"
ARKINDEX_API_SCHEMA_URL
"
)
...
...
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