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

refactor: use a Return fspecific or each case of the try the try #22

Merged
merged 1 commit into from
Sep 7, 2023
Merged
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
18 changes: 10 additions & 8 deletions pytest_copie/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,20 @@ def copy(self, extra_answers: dict = {}, template_dir: Any = None) -> Result:
unsafe=True,
)

# refresh project_dir with the generated one
# the project path will be the first child of the ouptut_dir
w_project_dir = next(d for d in worker.dst_path.glob("*") if d.is_dir())
w_answers = worker._answers_to_remember()
w_answers = {q: a for q, a in answers.items() if not q.startswith("_")}
w_exception, w_exit_code = None, 0
project_dir = next(d for d in worker.dst_path.glob("*") if d.is_dir())

# refresh answers with the generated ones
answers = worker._answers_to_remember()
answers = {q: a for q, a in answers.items() if not q.startswith("_")}

return Result(project_dir=project_dir, answers=answers)

except SystemExit as e:
w_exception, w_exit_code, w_project_dir, w_answers = e, e.code, None, {} # type: ignore
return Result(exception=e, exit_code=e.code)
except Exception as e:
w_exception, w_exit_code, w_project_dir, w_answers = e, -1, None, {} # type: ignore

return Result(w_exception, w_exit_code, w_project_dir, w_answers)
return Result(exception=e, exit_code=-1)


@pytest.fixture
Expand Down