Skip to content

Commit

Permalink
Improve error messages for misconfigured backend treatment (#7062)
Browse files Browse the repository at this point in the history
* Add testing warning if misconfig cant find nx-loopback

* fix lazy_import TypeError while creating error message for ModuleNotFoundError

* Update wording based on comments in dispatch mtg
  • Loading branch information
dschult authored and jarrodmillman committed Oct 27, 2023
1 parent a2c749a commit c9f8934
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion networkx/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ def pytest_configure(config):
)
else:
backends = entry_points(name="nx-loopback", group="networkx.backends")
networkx.utils.backends.backends["nx-loopback"] = next(iter(backends))
if backends:
networkx.utils.backends.backends["nx-loopback"] = next(iter(backends))
else:
warnings.warn(
"\n\n WARNING: Mixed NetworkX configuration! \n\n"
" This environment has mixed configuration for networkx.\n"
" The test object nx-loopback is not configured correctly.\n"
" You should not be seeing this message.\n"
" Try `pip install -e .`, or change your PYTHONPATH\n"
" Make sure python finds the networkx repo you are testing\n\n"
)


def pytest_collection_modifyitems(config, items):
Expand Down
2 changes: 1 addition & 1 deletion networkx/lazy_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __getattr__(self, x):
f"No module named '{fd['spec']}'\n\n"
"This error is lazily reported, having originally occurred in\n"
f' File {fd["filename"]}, line {fd["lineno"]}, in {fd["function"]}\n\n'
f'----> {"".join(fd["code_context"]).strip()}'
f'----> {"".join(fd["code_context"] or "").strip()}'
)


Expand Down

0 comments on commit c9f8934

Please sign in to comment.