Skip to content

fix(testing): don't change the output artifact location #758

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

Merged
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
5 changes: 2 additions & 3 deletions craft_application/commands/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,8 @@ def _run(

if parsed_args.test_path:
testing_service.validate_tests(parsed_args.test_path)
# Output into the spread directory.
parsed_args.output = pathlib.Path.cwd() / "spread"
parsed_args.output.mkdir(exist_ok=True)

parsed_args.output = pathlib.Path.cwd()
parsed_args.fetch_service_policy = None

# Don't enter a shell during the packing step, but save those values
Expand Down
1 change: 1 addition & 0 deletions docs/reference/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Fixes
- Enable terminal output when testing with ``--debug``, ``--shell``, or
``--shell-after`` parameters.
- Don't repull sources on test files changes.
- Generate artifacts for testing in the project root directory.
- Normalize the list of artifacts packed in ``PackageService`` to be relative
to the project root directory.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ prepare: |
execute: |
echo Running the test
env
test -f "$CRAFT_ARTIFACT"

restore: |
echo Restoring the test
43 changes: 43 additions & 0 deletions tests/unit/commands/test_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
PrimeCommand,
PullCommand,
StageCommand,
TestCommand,
get_lifecycle_command_group,
)
from craft_application.services.service_factory import ServiceFactory
Expand Down Expand Up @@ -851,3 +852,45 @@ def test_relativize_paths_invalid(root, paths):
[pathlib.Path(p) for p in paths], root=pathlib.Path(root)
)
assert str(raised.value) == "Cannot create packages outside of the project tree."


@pytest.mark.parametrize(
("debug", "shell", "shell_after", "tests"),
[
(False, False, False, None),
(True, True, True, "something"),
],
)
def test_test_run(
emitter, mock_services, app_metadata, debug, shell, shell_after, tests
):
mock_services.package.pack.return_value = [pathlib.Path("package.zip")]
parsed_args = argparse.Namespace(
destructive_mode=True,
parts=["my-part"],
debug=debug,
shell=shell,
shell_after=shell_after,
test_path=tests,
)
command = TestCommand(
{
"app": app_metadata,
"services": mock_services,
}
)

command.run(parsed_args)

mock_services.package.pack.assert_called_once_with(
mock_services.lifecycle.prime_dir,
pathlib.Path.cwd(),
)
mock_services.testing.test.assert_called_once_with(
pathlib.Path.cwd(),
pack_state=mock.ANY,
shell=shell,
shell_after=shell_after,
debug=debug,
tests=tests,
)
1 change: 1 addition & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def mock_services(monkeypatch, app_metadata, fake_project, project_path):
services.ServiceFactory.register(
"remote_build", mock.Mock(spec=services.RemoteBuildService)
)
services.ServiceFactory.register("testing", mock.Mock(spec=services.TestingService))

def forgiving_is_subclass(child, parent):
if not isinstance(child, type):
Expand Down
Loading