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
Merge requests
!59
Cache YAML payloads in tests
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Cache YAML payloads in tests
cache-yaml
into
master
Overview
0
Commits
1
Pipelines
1
Changes
1
Merged
Bastien Abadie
requested to merge
cache-yaml
into
master
4 years ago
Overview
0
Commits
1
Pipelines
1
Changes
1
Expand
Closes
#39 (closed)
Pytest execution went from 221.70s on
master
to 30.20s on this branch.
Edited
4 years ago
by
Bastien Abadie
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
99504a12
1 commit,
4 years ago
1 file
+
31
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
tests/conftest.py
+
31
−
1
Options
# -*- 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
"
)
Loading