Skip to content

Commit

Permalink
Merge pull request #1311 from ZLLentz/tst_failing_on_pip
Browse files Browse the repository at this point in the history
TST: reproduce and fix pypi failures
  • Loading branch information
ZLLentz authored Dec 5, 2024
2 parents 6a4e36f + 581d05c commit f7dc881
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
31 changes: 31 additions & 0 deletions docs/source/upcoming_release_notes/1311-tst_failing_on_pip.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
1311 tst_failing_on_pip
#######################

API Breaks
----------
- N/A

Library Features
----------------
- N/A

Device Features
---------------
- N/A

New Devices
-----------
- N/A

Bugfixes
--------
- N/A

Maintenance
-----------
- Make test_at2l0_clear_errors pass more consistently on CI.
- Add a utility for checking signal values that don't update promptly.

Contributors
------------
- zllentz
18 changes: 17 additions & 1 deletion pcdsdevices/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pkgutil
import shutil
import sys
import time
import warnings
from pathlib import Path
from types import ModuleType, SimpleNamespace
Expand All @@ -13,7 +14,7 @@
import ophyd
import pytest
from epics import PV
from ophyd.signal import LimitError
from ophyd.signal import LimitError, Signal
from ophyd.sim import FakeEpicsSignal, make_fake_device

from .. import analog_signals, lens, lxe
Expand Down Expand Up @@ -259,3 +260,18 @@ def post(self, *args, **kwargs):
self.posts.append((args, kwargs))

return MockELog('TST')


def wait_and_assert(sig: Signal, val: Any, tries: int = 10, wait: float = 0.1):
"""
Wait for sig's value to be val, asserting it after waiting.
This should be used when the timing of the value changing is not
fully deterministic, such as when its governed by the execution of a
background thread.
"""
for _ in range(tries):
if sig.get() == val:
break
time.sleep(wait)
assert sig.get() == val
3 changes: 2 additions & 1 deletion pcdsdevices/tests/test_attenuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from ..attenuator import (AT1K2, AT1K4, AT2K2, AT2L0, MAX_FILTERS, AttBase,
Attenuator, _att_classes)
from .conftest import wait_and_assert

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -261,4 +262,4 @@ def test_at2l0_clear_errors(at2l0):
assert not sig.get()
at2l0.clear_errors()
for sig in signals:
assert sig.get()
wait_and_assert(sig, 1)

0 comments on commit f7dc881

Please sign in to comment.