Skip to content

Commit

Permalink
add profile run to ci
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Sep 23, 2024
1 parent c55c3da commit f8ad5d1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,13 @@ jobs:
default_python: '3.11'
envs: |
- linux: compatibility
profile:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
with:
submodules: false
# Any env name which does not start with `pyXY` will use this Python version.
default_python: '3.12'
envs: |
- linux: profile
artifact-path: .profiles/*
24 changes: 24 additions & 0 deletions asdf/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path

import pytest

Expand All @@ -8,6 +9,29 @@
collect_ignore = ["asdf.py", "stream.py"]


try:
from pyinstrument import Profiler

TESTS_ROOT = Path.cwd()

@pytest.fixture(autouse=True)
def auto_profile(request):
PROFILE_ROOT = TESTS_ROOT / ".profiles"
# Turn profiling on
profiler = Profiler()
profiler.start()

yield # Run test

profiler.stop()
PROFILE_ROOT.mkdir(exist_ok=True)
results_file = PROFILE_ROOT / f"{request.node.name}.html"
profiler.write_html(results_file)

except ImportError:
pass


def pytest_collection_modifyitems(items):
# Turn warnings into errors for all tests, this is needed
# as running tests through pyargs will not use settings
Expand Down
8 changes: 8 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env_list =
weldx
sunpy
dkist
profile

[testenv]
set_env =
Expand Down Expand Up @@ -324,3 +325,10 @@ commands =
# https://github.com/sunpy/sunpy/pull/7432
pytest dkist --benchmark-skip \
-W "ignore::asdf.exceptions.AsdfManifestURIMismatchWarning"

[testenv:profile]
commands_pre =
pip install pyinstrument
pip freeze
commands =
pyinstrument -m pytest {posargs}

0 comments on commit f8ad5d1

Please sign in to comment.