Skip to content

Commit

Permalink
test: better tooling for debugging uuid generation in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sassanh committed Sep 26, 2024
1 parent 9ab2621 commit 3d4a02c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- refactor(core): truncate long log items for log level `DEBUG` or lower to avoid cluttering the logs
- refactor(tests): add a delay between initializing different services to make sure they always run in the same order
- feat(rpc): add `subscribe_event` to the rpc service to let external services subscribe to events - closes #1
- test: better tooling for debugging uuid generation in tests

## Version 0.16.2

Expand Down
38 changes: 19 additions & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions tests/fixtures/mock_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,35 +86,34 @@ def now(cls: type[DateTime], tz: datetime.tzinfo | None = None) -> DateTime:


def _monkeypatch_uuid(monkeypatch: pytest.MonkeyPatch) -> None:
from fake import Fake
import uuid

counter = 0

def debug_uuid4() -> Fake:
def debug_uuid4() -> uuid.UUID:
nonlocal counter
counter += 1
import logging
import traceback

generated_uuid = uuid.UUID(int=random.getrandbits(128))

logging.debug(
'`uuid.uuid4` is being called',
extra={
'traceback': '\n'.join(traceback.format_stack()[:-1]),
'counter': counter,
'generated_uuid': generated_uuid.hex,
},
)

result = Fake()
result.hex = f'{counter}'
return result
return generated_uuid

from ubo_app.constants import DEBUG_MODE_TEST_UUID

if DEBUG_MODE_TEST_UUID:
monkeypatch.setattr('uuid.uuid4', debug_uuid4)
else:
import uuid

monkeypatch.setattr(
uuid,
'uuid4',
Expand Down

0 comments on commit 3d4a02c

Please sign in to comment.