Browse Source

ci(test): dump test time result to json file

GitOrigin-RevId: 0ed092a0e8
tags/v0.3.2
Megvii Engine Team 5 years ago
parent
commit
0bdb64c5f9
4 changed files with 27 additions and 3 deletions
  1. +2
    -1
      python_module/requires-test.txt
  2. +1
    -1
      python_module/setup.py
  3. +23
    -1
      python_module/test/conftest.py
  4. +1
    -0
      python_module/test/run.sh

+ 2
- 1
python_module/requires-test.txt View File

@@ -1,2 +1,3 @@
pytest==5.3.0 pytest==5.3.0
pytest-sphinx==0.2.2
pytest-sphinx>=0.2.2
pytest-json-report>=1.2.1

+ 1
- 1
python_module/setup.py View File

@@ -76,7 +76,7 @@ setup_kwargs = dict(
ext_modules=[PrecompiledExtesion('megengine._internal._mgb')], ext_modules=[PrecompiledExtesion('megengine._internal._mgb')],
install_requires=requires, install_requires=requires,
extras_require={ extras_require={
'dev': [*requires_style, *requires_test],
'dev': requires_style + requires_test,
'ci': requires_test, 'ci': requires_test,
}, },
cmdclass={'build_ext': build_ext}, cmdclass={'build_ext': build_ext},


+ 23
- 1
python_module/test/conftest.py View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# MegEngine is Licensed under the Apache License, Version 2.0 (the "License") # MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
# #
# Copyright (c) 2014-2020 Megvii Inc. All rights reserved. # Copyright (c) 2014-2020 Megvii Inc. All rights reserved.
@@ -10,3 +9,26 @@ import os
import sys import sys


sys.path.append(os.path.join(os.path.dirname(__file__))) sys.path.append(os.path.join(os.path.dirname(__file__)))


def pytest_json_modifyreport(json_report):
events = []
timestamp = 0
for item in json_report["tests"]:
for stage in ["setup", "call", "teardown"]:
if stage in item:
events.append(
{
"name": item["nodeid"],
"ph": "X",
"ts": timestamp,
"dur": item[stage]["duration"] * 1e6,
"cat": stage,
"pid": stage,
"tid": item["nodeid"],
}
)
timestamp += events[-1]["dur"]
json_report["traceEvents"] = events
del json_report["collectors"]
del json_report["tests"]

+ 1
- 0
python_module/test/run.sh View File

@@ -2,6 +2,7 @@


pushd $(dirname "${BASH_SOURCE[0]}")/.. >/dev/null pushd $(dirname "${BASH_SOURCE[0]}")/.. >/dev/null
pytest -xv -m 'not internet' \ pytest -xv -m 'not internet' \
--json-report --json-report-file=time_python_test.json \
--ignore test/unit/module/test_pytorch.py \ --ignore test/unit/module/test_pytorch.py \
--ignore test/pytorch_comparison \ --ignore test/pytorch_comparison \
--ignore test/unit/hub/test_hub.py \ --ignore test/unit/hub/test_hub.py \


Loading…
Cancel
Save