Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pytest fixes #556

Merged
merged 3 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions brownie/_cli/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def main():
if project_path is None:
raise ProjectNotFound

# ensure imports are possible from anywhere in the project
project.main._add_to_sys_path(project_path)

if args["<path>"] is None:
args["<path>"] = project_path.joinpath("tests").as_posix()

Expand Down
8 changes: 5 additions & 3 deletions brownie/project/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ def _get_ast_hash(path: str) -> str:
with Path(path).open() as fp:
ast_list = [ast.parse(fp.read(), path)]
base_path = str(check_for_project(path))
for obj in [i for i in ast_list[0].body if type(i) in (ast.Import, ast.ImportFrom)]:
if type(obj) is ast.Import:

for obj in [i for i in ast_list[0].body if isinstance(i, (ast.Import, ast.ImportFrom))]:
if isinstance(obj, ast.Import):
name = obj.names[0].name # type: ignore
else:
name = obj.module # type: ignore
Expand All @@ -115,8 +116,9 @@ def _get_ast_hash(path: str) -> str:
ImportWarning,
)
continue
if base_path in origin:
if origin is not None and base_path in origin:
with open(origin) as fp:
ast_list.append(ast.parse(fp.read(), origin))

dump = "\n".join(ast.dump(i) for i in ast_list)
return sha1(dump.encode()).hexdigest()
14 changes: 11 additions & 3 deletions brownie/test/plugin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/python3

import pytest

from brownie import project
from brownie._config import CONFIG
from brownie.test.fixtures import PytestBrownieFixtures
from brownie.test.managers import PytestBrownieMaster, PytestBrownieRunner, PytestBrownieXdistRunner
from brownie.utils import color


# set commandline options
Expand Down Expand Up @@ -45,9 +48,14 @@ def pytest_addoption(parser):
def pytest_configure(config):
if project.check_for_project("."):

active_project = project.load()
active_project.load_config()
active_project._add_to_main_namespace()
try:
active_project = project.load()
active_project.load_config()
active_project._add_to_main_namespace()
except Exception as e:
# prevent pytest INTERNALERROR traceback when project fails to compile
print(f"{color.format_tb(e)}\n")
raise pytest.UsageError("Unable to load project")

# enable verbose output if stdout capture is disabled
if config.getoption("capture") == "no":
Expand Down