Skip to content

Simplify and improve test_packages.py #2219

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 1 commit into from
Feb 18, 2025

Conversation

mathbunnyru
Copy link
Member

Describe your changes

Issue ticket if applicable

Checklist (especially for first-time contributors)

  • I have performed a self-review of my code
  • If it is a core feature, I have added thorough tests
  • I will try not to use force-push to make the review process easier for reviewers
  • I have updated the documentation for significant changes

@@ -95,30 +95,21 @@ def package_helper(container: TrackedContainer) -> CondaPackageHelper:


@pytest.fixture(scope="function")
def packages(package_helper: CondaPackageHelper) -> dict[str, set[str]]:
def requested_packages(package_helper: CondaPackageHelper) -> dict[str, set[str]]:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This better shows an intention


def python_package_predicate(package: str) -> bool:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having so many predicates makes code difficult to read

assert (
exec_result.exit_code == 0
), f"Import package failed, output: {exec_result.output}"
assert exec_result.exit_code == 0, exec_result.output.decode("utf-8")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This .decode("utf-8") is the most important part of this PR - currently, logs are difficult to read, because they are printed as binary strings.
I've checked after change and logs are much better if some import fails.

if len(failures) > 0:
raise AssertionError(failures)
failed_imports.append(package)
LOGGER.error(f"Failed to import package: {package}, output:\n {err}")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nesting error message in a json makes it much worse when printing, simple LOGGER.error looks much better.
The downside is that there are several messages instead of one, but I actually prefer reading several beautiful messages than one unreadable json.

@mathbunnyru mathbunnyru merged commit 66260f8 into jupyter:main Feb 18, 2025
65 checks passed
@mathbunnyru
Copy link
Member Author

mathbunnyru commented Feb 18, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant