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

Set App.app to initial value of None to avoid AttributeError in teardown #2918

Merged
merged 3 commits into from
Oct 17, 2024

Conversation

HalfWhitt
Copy link
Contributor

@HalfWhitt HalfWhitt commented Oct 17, 2024

Running the entire core test suite completes successfully. But at least one test (and probably others), when run individually, fail. Running tests/style/pack/layout/test_rtl.py by itself gets six instances of this:

    @pytest.fixture(autouse=True)
    def no_dangling_tasks():
        """Ensure any tasks for the test were removed when the test finished."""
        yield
>       if toga.App.app:
E       AttributeError: type object 'App' has no attribute 'app'

tests/conftest.py:22: AttributeError

This is fine if a previous test has created an app instance, which is why it only fails in isolation. Changing it to a hasattr check fixes it, but then it still needs an additional truthiness or None check to avoid failing test_window_created_without_app, which sets App.app to None. At that point, why not just set None as the initial value in the class definition? It makes semantic sense for it to be None if there's no running app.

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

Seems entirely reasonable. Thanks for the fix!

@freakboy3742 freakboy3742 merged commit 261e356 into beeware:main Oct 17, 2024
40 checks passed
@HalfWhitt HalfWhitt deleted the app-condtional branch October 17, 2024 03:44
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.

2 participants