Skip to content

Commit

Permalink
Fixing hot reload interaction with pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
HammadTheOne committed Aug 11, 2021
1 parent 5d41353 commit e169cbc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import collections
import importlib
from importlib.machinery import ModuleSpec
import json
import pkgutil
import threading
Expand All @@ -17,6 +18,7 @@
import plotly

from future.moves.urllib.parse import urlparse
from _pytest.assertion.rewrite import AssertionRewritingHook

import flask
from flask_compress import Compress
Expand Down Expand Up @@ -1462,8 +1464,20 @@ def enable_dev_tools(
if x != "__main__"
]

# # additional condition to account for AssertionRewritingHook object
# # loader when running pytest
for index, package in enumerate(packages):
if isinstance(package, AssertionRewritingHook):
print("YES")
dash_spec = importlib.util.find_spec("dash")
dash_test_path = dash_spec.submodule_search_locations[0]
setattr(dash_spec, "path", dash_test_path)
packages[index] = dash_spec

component_packages_dist = [
os.path.dirname(package.path)
dash_test_path
if isinstance(package, ModuleSpec)
else os.path.dirname(package.path)
if hasattr(package, "path")
else package.filename
for package in packages
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/devtools/test_hot_reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def new_text(n):
try:
until(
lambda: dash_duo.driver.execute_script("return window.cheese") == "gouda",
timeout=3,
timeout=10,
)
finally:
sleep(1) # ensure a new mod time
Expand All @@ -98,7 +98,7 @@ def new_text(n):

until(
lambda: dash_duo.driver.execute_script("return window.cheese") == "roquefort",
timeout=3,
timeout=10,
)

# we've done a hard reload so someVar is gone
Expand Down

0 comments on commit e169cbc

Please sign in to comment.