Skip to content

Commit

Permalink
respond to comments and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
leej3 committed May 23, 2024
1 parent 0fa13cc commit 15acf1d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/hvd-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
timeout_minutes: 15
shell: bash
command: bash tests/run_cpu_tests.sh
new_command_on_retry: USE_LAST_FAILED=1 bash tests/run_cpu_tests.sh
new_command_on_retry: USE_LAST_FAILED=1 bash tests/run_cpu_tests.sh

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pytorch-version-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
timeout_minutes: 15
shell: bash
command: bash tests/run_cpu_tests.sh "not test_time_profilers"
new_command_on_retry: USE_LAST_FAILED=1 bash tests/run_cpu_tests.sh "not test_time_profilers"
new_command_on_retry: USE_LAST_FAILED=1 bash tests/run_cpu_tests.sh "not test_time_profilers"

# create-issue:
# runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tpu-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
command: |
python -c "import torch_xla; print('torch xla version:', torch_xla.__version__)"
bash tests/run_tpu_tests.sh
new_command_on_retry: USE_LAST_FAILED=1 bash tests/run_tpu_tests.sh
new_command_on_retry: USE_LAST_FAILED=1 bash tests/run_tpu_tests.sh
env:
LD_LIBRARY_PATH: ${{ env.LD_LIBRARY_PATH }}:${{ env.Python_ROOT_DIR }}/lib
XRT_DEVICE_MAP: "CPU:0;/job:localservice/replica:0/task:0/device:XLA_CPU:0"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
timeout_minutes: 15
shell: bash
command: SKIP_DISTRIB_TESTS=${{ matrix.skip-distrib-tests }} bash tests/run_cpu_tests.sh
new_command_on_retry: USE_LAST_FAILED=1 SKIP_DISTRIB_TESTS=${{ matrix.skip-distrib-tests }} bash tests/run_cpu_tests.sh
new_command_on_retry: USE_LAST_FAILED=1 SKIP_DISTRIB_TESTS=${{ matrix.skip-distrib-tests }} bash tests/run_cpu_tests.sh

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
Expand Down
66 changes: 47 additions & 19 deletions tests/ignite/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,51 @@
import ignite.distributed as idist


def pytest_configure(config):
config.addinivalue_line("markers", "distributed: run distributed")
config.addinivalue_line("markers", "multinode_distributed: distributed")
config.addinivalue_line("markers", "tpu: run on tpu")
if config.option.treat_unrun_as_failed:
unrun_tracker = UnrunTracker()
config.pluginmanager.register(unrun_tracker, "unrun_tracker_plugin")


def pytest_addoption(parser):
"""
Add custom command line options for the ignite test suite here.
See:
This function is a pytest hook (due to its name) and is *"automatically"
executed at the start of a test run
https://docs.pytest.org/en/latest/reference/reference.html#initialization-hooks
* "automatically" is true provided this conftest.py file is the
root directory. See:
https://docs.pytest.org/en/latest/reference/customize.html#initialization-determining-rootdir-and-configfile
"""
parser.addoption(
"--treat-unrun-as-failed",
action="store_true",
help="""
If a session is interrupted treat the unrun tests as failed so that a
If a session is interrupted, treat the unrun tests as failed so that a
rerun with --last-failed runs any tests that have not passed or been
skipped.
skipped. Note that if all tests in a module have been skipped, the
module will be skipped for all subsequent runs.
""",
)


def pytest_configure(config):
"""
This function is a pytest hook (due to its name) and is run after command
line parsing is complete in order to configure the test session.
"""
config.addinivalue_line("markers", "distributed: run distributed")
config.addinivalue_line("markers", "multinode_distributed: distributed")
config.addinivalue_line("markers", "tpu: run on tpu")
if config.option.treat_unrun_as_failed:
unrun_tracker = UnrunTracker()
config.pluginmanager.register(unrun_tracker, "unrun_tracker_plugin")


@pytest.fixture(scope="session", autouse=True)
def term_handler():
# This allows the pytest session to be terminated upon retries on CI. It may
# be worth using this fixture solely in that context. For a discussion on
# whether sigterm should be ignored see:
# https://github.com/pytest-dev/pytest/issues/5243
"""
This allows the pytest session to be terminated upon retries on CI. It may
be worth using this fixture solely in that context. For a discussion on
whether sigterm should be ignored and why pytest usually ignores it see:
https://github.com/pytest-dev/pytest/issues/5243
"""
if threading.current_thread() is threading.main_thread() and hasattr(signal, "SIGTERM"):
orig = signal.signal(signal.SIGTERM, signal.getsignal(signal.SIGINT))
yield
Expand Down Expand Up @@ -480,10 +498,13 @@ def distributed(request, local_rank, world_size):

class UnrunTracker:
"""
Keeps track of unrun tests to improve the user experience when a test
session is interrupted. This is particularly useful on CI when rerunning
"failing" tests where the failure was due to a deadlock and many tests
weren't actually run so they didn't actually fail.
Keeps track of unrun tests to improve the user experience when using the
"--last-failed" pytest option and a test session is interrupted. This is
particularly useful on CI when rerunning "failing" tests where the failure
was due to a deadlock and many tests weren't actually run so they didn't
actually fail. This is a pytest plugin that implements some standard hooks
to modify the test session. Its functionality can be added to a test session
by registering it with the pytest plugin manager.
"""

def __init__(self):
Expand Down Expand Up @@ -573,6 +594,13 @@ def xla_worker(index, fn):


def pytest_sessionfinish(session, exitstatus):
"""
Any functionality that should be run at the end of the session should be
added here.
This is a pytest hook (due to its name) and is called after the whole test
run finished, right before returning the exit status to the system.
"""
# If requested by the user, track all unrun tests and add them to the lastfailed cache
if session.config.option.treat_unrun_as_failed:
unrun_tracker = session.config.pluginmanager.get_plugin("unrun_tracker_plugin")
unrun_tracker.record_unrun_as_failed(session, exitstatus)

0 comments on commit 15acf1d

Please sign in to comment.