Skip to content

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

Merged
freakboy3742 merged 3 commits into
beeware:mainfrom
HalfWhitt:app-condtional
Oct 17, 2024
Merged

Set App.app to initial value of None to avoid AttributeError in teardown#2918
freakboy3742 merged 3 commits into
beeware:mainfrom
HalfWhitt:app-condtional

Conversation

@HalfWhitt

@HalfWhitt HalfWhitt commented Oct 17, 2024

Copy link
Copy Markdown
Member

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

@freakboy3742 freakboy3742 left a comment

Copy link
Copy Markdown
Member

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
@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