Skip to content

Commit

Permalink
change code to install debug in fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Apr 5, 2023
1 parent 03ffc26 commit 8f1cc64
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
18 changes: 11 additions & 7 deletions devtools/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
# language=python
install_code = """
# add devtools `debug` function to builtins
import builtins
try:
from devtools import debug
except ImportError:
pass
else:
setattr(builtins, 'debug', debug)
import sys
# we don't install here for pytest as it breaks pytest, it is
# installed later by a pytest fixture
if not sys.argv[0].endswith('pytest'):
import builtins
try:
from devtools import debug
except ImportError:
pass
else:
setattr(builtins, 'debug', debug)
"""


Expand Down
7 changes: 6 additions & 1 deletion devtools/pytest_plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations as _annotations

import ast
import builtins
import sys
import textwrap
from contextvars import ContextVar
Expand All @@ -15,6 +16,8 @@
import pytest
from executing import Source

from . import debug

if TYPE_CHECKING:
pass

Expand Down Expand Up @@ -79,7 +82,9 @@ def pytest_addoption(parser: Any) -> None:
@pytest.fixture(scope='session', autouse=True)
def insert_assert_add_to_builtins() -> None:
try:
__builtins__['insert_assert'] = insert_assert
setattr(builtins, 'insert_assert', insert_assert)
# we also install debug here since the default script doesn't install it
setattr(builtins, 'debug', debug)
except TypeError:
# happens on pypy
pass
Expand Down

0 comments on commit 8f1cc64

Please sign in to comment.