forked from pytorch/rl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
88 lines (76 loc) · 2.43 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
import time
import warnings
from collections import defaultdict
import pytest
CALL_TIMES = defaultdict(lambda: 0.0)
def pytest_sessionfinish(maxprint=50):
out_str = """
Call times:
===========
"""
keys = list(CALL_TIMES.keys())
if len(keys) > 1:
maxchar = max(*[len(key) for key in keys])
elif len(keys) == 1:
maxchar = len(keys[0])
else:
return
for i, (key, item) in enumerate(
sorted(CALL_TIMES.items(), key=lambda x: x[1], reverse=True)
):
spaces = " " + " " * (maxchar - len(key))
out_str += f"\t{key}{spaces}{item: 4.4f}s\n"
if i == maxprint - 1:
break
print(out_str)
@pytest.fixture(autouse=True)
def measure_duration(request: pytest.FixtureRequest):
start_time = time.time()
def fin():
duration = time.time() - start_time
name = request.node.name
class_name = request.cls.__name__ if request.cls else None
name = name.split("[")[0]
if class_name is not None:
name = "::".join([class_name, name])
file = os.path.basename(request.path)
name = f"{file}::{name}"
CALL_TIMES[name] = CALL_TIMES[name] + duration
request.addfinalizer(fin)
@pytest.fixture(scope="session", autouse=True)
def set_warnings() -> None:
warnings.filterwarnings(
"ignore",
category=UserWarning,
message=r"Lazy modules are a new feature under heavy development",
)
warnings.filterwarnings(
"ignore",
category=UserWarning,
message=r"Couldn't cast the policy onto the desired device on remote process",
)
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message=r"Deprecated call to `pkg_resources.declare_namespace",
)
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message=r"Using or importing the ABCs",
)
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message=r"Please use `coo_matrix` from the `scipy.sparse` namespace",
)
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message=r"jax.tree_util.register_keypaths is deprecated|jax.ShapedArray is deprecated",
)