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

Fix missing markers and opening rule violation #3725

Merged
merged 3 commits into from
Dec 14, 2024

Conversation

DoctorJohn
Copy link
Member

@DoctorJohn DoctorJohn commented Dec 14, 2024

Description

This PR (hopefully) fixes the following errors currently thrown by our Windows CI:

FAILED \U0001f630  tests/extensions/test_pyinstrument.py::test_basic_pyinstrument - PermissionError: [Errno 13] Permission denied: 'C:\\\\Users\\\\RUNNER~1\\\\AppData\\\\Local\\\\Temp\\\\tmprp5tslzd'
ERROR \U0001f621  tests/channels/test_layers.py::test_channel_listen - RuntimeError: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.
ERROR \U0001f621  tests/channels/test_layers.py::test_channel_listen_with_confirmation - RuntimeError: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.
ERROR \U0001f621  tests/channels/test_layers.py::test_channel_listen_timeout - RuntimeError: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.
ERROR \U0001f621  tests/channels/test_layers.py::test_channel_listen_timeout_cm - RuntimeError: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.
ERROR \U0001f621  tests/channels/test_layers.py::test_channel_listen_no_message_on_channel - RuntimeError: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.
ERROR \U0001f621  tests/channels/test_layers.py::test_channel_listen_no_message_on_channel_cm - RuntimeError: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.
ERROR \U0001f621  tests/channels/test_layers.py::test_channel_listen_group - RuntimeError: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.
ERROR \U0001f621  tests/channels/test_layers.py::test_channel_listen_group_cm - RuntimeError: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.
ERROR \U0001f621  tests/channels/test_layers.py::test_channel_listen_group_twice - RuntimeError: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.

The PermissionError is caused by our incorrect usage of tempfile.NamedRemporaryFile on Windows. The corresponding docs outline some rules that must be followed on Windows when a named file is opened. Not deleting the temporary file appears to be the easiest solution (CI is cleaning up afterward anyway).

The other errors are all related to missing markers. I'm not sure why these tests only fail under Windows. We also set these markers for other Channels tests, so let's try the same here.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Summary by Sourcery

Fix test failures on Windows by addressing PermissionError in test_pyinstrument and adding missing django_db markers to channel layer tests.

Bug Fixes:

  • Fix PermissionError in test_pyinstrument by setting delete=False for NamedTemporaryFile on Windows.
  • Add missing django_db markers to channel layer tests to prevent RuntimeError related to database access.

Copy link
Contributor

sourcery-ai bot commented Dec 14, 2024

Reviewer's Guide by Sourcery

This PR addresses two issues: a Windows CI permission error in pyinstrument tests by modifying temporary file handling, and missing Django database markers in channel layer tests. The implementation involves adding the django_db marker to multiple test functions and modifying the NamedTemporaryFile usage to prevent file deletion on Windows.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Modified temporary file handling in pyinstrument test to fix Windows permission error
  • Changed NamedTemporaryFile to not delete the file after use by setting delete=False
  • Added assertion to verify result.data exists
tests/extensions/test_pyinstrument.py
Added Django database markers to channel layer tests
  • Added @pytest.mark.django_db decorator to all channel listen test functions
  • Applied the marker to tests involving group operations
  • Applied the marker to tests involving timeout scenarios
tests/channels/test_layers.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @DoctorJohn - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

codspeed-hq bot commented Dec 14, 2024

CodSpeed Performance Report

Merging #3725 will not alter performance

Comparing DoctorJohn:fix-windows-ci (7508237) with main (6ea5514)

Summary

✅ 21 untouched benchmarks

Copy link

codecov bot commented Dec 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.46%. Comparing base (6ea5514) to head (7508237).
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3725       +/-   ##
===========================================
- Coverage   97.02%   65.46%   -31.56%     
===========================================
  Files         503      498        -5     
  Lines       33658    32507     -1151     
  Branches     5608     1670     -3938     
===========================================
- Hits        32658    21282    -11376     
- Misses        793    10906    +10113     
- Partials      207      319      +112     

@DoctorJohn DoctorJohn merged commit 7a42b03 into strawberry-graphql:main Dec 14, 2024
92 of 96 checks passed
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