Skip to content

Commit cd2ff7c

Browse files
authored
Merge pull request #1493 from plotly/import-test
improve dash import test
2 parents 2fa1883 + a06e12b commit cd2ff7c

File tree

7 files changed

+34
-35
lines changed

7 files changed

+34
-35
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to `dash` will be documented in this file.
33
This project adheres to [Semantic Versioning](https://semver.org/).
44

5+
## [UNRELEASED]
6+
### Fixed
7+
- [#1493](https://github.com/plotly/dash/pull/1493) Fix [#1143](https://github.com/plotly/dash/issues/1143), a bug where having a file with one of several common names (test.py, code.py, org.py, etc) that imports a dash component package would make `import dash` fail with a cryptic error message asking whether you have a file named "dash.py"
8+
59
## [1.18.1] - 2020-12-09
610

711
## [1.18.0] - 2020-12-07

dash/__init__.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
from .dash import Dash, no_update # noqa: F401
2-
from . import dependencies # noqa: F401
3-
from . import development # noqa: F401
4-
from . import exceptions # noqa: F401
5-
from . import resources # noqa: F401
6-
from .version import __version__ # noqa: F401
7-
from ._callback_context import callback_context # noqa: F401
1+
# pylint: disable=C0413
2+
# __plotly_dash is for the "make sure you don't have a dash.py" check
3+
# must come before any other imports.
4+
__plotly_dash = True
5+
from .dash import Dash, no_update # noqa: F401,E402
6+
from . import dependencies # noqa: F401,E402
7+
from . import development # noqa: F401,E402
8+
from . import exceptions # noqa: F401,E402
9+
from . import resources # noqa: F401,E402
10+
from .version import __version__ # noqa: F401,E402
11+
from ._callback_context import callback_context # noqa: F401,E402

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"private::test.unit-dash": "pytest tests/unit",
2323
"private::test.unit-renderer": "cd dash-renderer && npm run test",
2424
"private::test.integration-dash": "TESTFILES=$(circleci tests glob \"tests/integration/**/test_*.py\" | circleci tests split --split-by=timings) && pytest --headless --nopercyfinalize --junitxml=test-reports/junit_intg.xml ${TESTFILES}",
25+
"private::test.integration-dash-import": "cd tests/integration/dash && python dash_import_test.py",
2526
"format": "run-s private::format.*",
2627
"initialize": "run-s private::initialize.*",
2728
"lint": "run-s private::lint.*",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# NOTE: this is NOT a pytest test. Just run it as a regular Python script.
2+
# pytest does some magic that makes the issue we're trying to test disappear.
3+
4+
import types
5+
import os
6+
7+
import dash
8+
9+
assert isinstance(dash, types.ModuleType), "dash can be imported"
10+
11+
this_dir = os.path.dirname(__file__)
12+
with open(os.path.join(this_dir, "../../../dash/version.py")) as fp:
13+
assert dash.__version__ in fp.read(), "version is consistent"
14+
15+
assert getattr(dash, "Dash").__name__ == "Dash", "access to main Dash class is valid"

tests/integration/dash/org.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# used implicitly by dash_import_test
2+
# to test https://github.com/plotly/dash/issues/1143
3+
import dash_core_components as dcc # noqa: F401

tests/unit/dash/test_dash_import.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/unit/test_import.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)