Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MLAir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
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
esde
machine-learning
MLAir
Commits
18910fde
Commit
18910fde
authored
5 years ago
by
lukas leufen
Browse files
Options
Downloads
Patches
Plain Diff
pytest_runtest_teardown runs now a proper clean up
parent
e14f3474
No related branches found
No related tags found
2 merge requests
!24
include recent development
,
!20
not distributed training
Pipeline
#27158
passed
5 years ago
Stage: test
Stage: pages
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
conftest.py
+18
-6
18 additions, 6 deletions
conftest.py
with
18 additions
and
6 deletions
conftest.py
+
18
−
6
View file @
18910fde
...
@@ -3,11 +3,23 @@ import shutil
...
@@ -3,11 +3,23 @@ import shutil
def
pytest_runtest_teardown
(
item
,
nextitem
):
def
pytest_runtest_teardown
(
item
,
nextitem
):
"""
Teardown method to clean up folder creations during testing. This method is called after each test, but performs
deletions only after an entire test class was executed.
:param item: tested item
:param nextitem: next item (could be None, if no following test is available)
"""
if
nextitem
is
None
or
item
.
cls
!=
nextitem
.
cls
:
if
nextitem
is
None
or
item
.
cls
!=
nextitem
.
cls
:
print
(
f
"
\n
new class:
{
item
.
cls
}
->
{
nextitem
.
cls
if
nextitem
else
None
}
"
)
# clean up all TestExperiment and data folder that have been created during testing
print
(
f
"
\n
{
nextitem
.
fspath
.
dirname
}
"
)
rel_path
=
os
.
path
.
relpath
(
item
.
fspath
.
dirname
,
os
.
path
.
abspath
(
__file__
))
if
"
data
"
in
os
.
listdir
(
item
.
fspath
.
dirname
):
path
=
os
.
path
.
dirname
(
__file__
)
print
(
"
found data
"
)
for
stage
in
filter
(
None
,
rel_path
.
replace
(
"
..
"
,
"
.
"
).
split
(
"
/
"
)):
shutil
.
rmtree
(
os
.
path
.
join
(
item
.
fspath
.
dirname
,
"
data
"
),
ignore_errors
=
True
)
path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
path
,
stage
))
list_dir
=
os
.
listdir
(
path
)
if
"
data
"
in
list_dir
and
path
!=
os
.
path
.
dirname
(
__file__
):
# do not delete data folder in src
shutil
.
rmtree
(
os
.
path
.
join
(
path
,
"
data
"
),
ignore_errors
=
True
)
if
"
TestExperiment
"
in
list_dir
:
shutil
.
rmtree
(
os
.
path
.
join
(
path
,
"
TestExperiment
"
),
ignore_errors
=
True
)
else
:
else
:
print
(
f
"
\n
same class:
{
item
.
cls
}
==
{
nextitem
.
cls
}
"
)
pass
# nothing to do if next test is from same test class
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