Skip to content

Commit 5647abe

Browse files
authored
Fix pytest import (#1720)
* Adding pytest install * Adding import check * Fixing tests/linting * Removing unnecessary object inheritance
1 parent eae8914 commit 5647abe

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

dash/_callback.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from . import _validate
2323

2424

25-
class NoUpdate(object):
25+
class NoUpdate:
2626
# pylint: disable=too-few-public-methods
2727
pass
2828

dash/dash.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import print_function
22

3-
from functools import wraps
43
import os
54
import sys
65
import collections
@@ -16,7 +15,6 @@
1615
import base64
1716

1817
from future.moves.urllib.parse import urlparse
19-
from _pytest.assertion.rewrite import AssertionRewritingHook
2018

2119
import flask
2220
from flask_compress import Compress
@@ -1708,13 +1706,18 @@ def enable_dev_tools(
17081706

17091707
# # additional condition to account for AssertionRewritingHook object
17101708
# # loader when running pytest
1711-
for index, package in enumerate(packages):
1712-
if isinstance(package, AssertionRewritingHook):
1713-
print("YES")
1714-
dash_spec = importlib.util.find_spec("dash")
1715-
dash_test_path = dash_spec.submodule_search_locations[0]
1716-
setattr(dash_spec, "path", dash_test_path)
1717-
packages[index] = dash_spec
1709+
1710+
if "_pytest" in sys.modules:
1711+
from _pytest.assertion.rewrite import ( # pylint: disable=import-outside-toplevel
1712+
AssertionRewritingHook,
1713+
)
1714+
1715+
for index, package in enumerate(packages):
1716+
if isinstance(package, AssertionRewritingHook):
1717+
dash_spec = importlib.util.find_spec("dash")
1718+
dash_test_path = dash_spec.submodule_search_locations[0]
1719+
setattr(dash_spec, "path", dash_test_path)
1720+
packages[index] = dash_spec
17181721

17191722
component_packages_dist = [
17201723
dash_test_path

tests/integration/callbacks/test_global_dash_callback.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import dash_core_components as dcc
2-
import dash_html_components as html
31
import dash
4-
from dash.dependencies import Input, Output
2+
from dash import Input, Output, dcc, html
53

64

75
def test_dash_callback_001(dash_duo):

0 commit comments

Comments
 (0)