-
-
Notifications
You must be signed in to change notification settings - Fork 313
Fix: Correct test file placement for Django test discovery #4752
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: Correct test file placement for Django test discovery #4752
Conversation
WalkthroughUpdated import statements in the test module to reference models from the parent package level instead of the current package, changing relative import path from Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
website/tests/test_main.py (3)
35-35: Avoid hardcoding the live server port to reduce CI flakiness.Hardcoding
DJANGO_LIVE_TEST_SERVER_ADDRESS = "localhost:8082"can collide if the port is in use on CI runners. Let Django pick a free port unless a fixed port is required.-os.environ["DJANGO_LIVE_TEST_SERVER_ADDRESS"] = "localhost:8082" +# Prefer default ephemeral port selection to avoid collisions on CI: +# os.environ["DJANGO_LIVE_TEST_SERVER_ADDRESS"] = "localhost:8082"
78-83: Modernize Selenium locators and waits (Selenium 4).Use
By.*locators consistently (you already importBy) and favorWebDriverWaitovertime.sleepfor stability. This reduces deprecation warnings and flakes.Example pattern:
-username = self.selenium.find_element("name", "username") +username = self.selenium.find_element(By.NAME, "username") -# Wait for any animations to complete -time.sleep(1) +# Wait for the button to be clickable instead of sleeping +WebDriverWait(self.selenium, 10).until(EC.element_to_be_clickable((By.NAME, "signup_button")))Repeat similarly for other
find_element("name"/"id"/"tag name", ...)calls in these ranges.Also applies to: 91-94, 99-104, 136-139, 150-153, 158-165, 175-178, 180-188
237-244: Use direct assertion helpers for clarity.Replace unconditional asserts with direct intent‑revealing helpers.
- if default_storage.exists(filename): - self.assertTrue(False, "files exist") + self.assertFalse(default_storage.exists(filename), "Screenshot file should be removed from storage") ... - if "hidden" not in filename: - self.assertFalse(True, "files rename failed") + self.assertIn("hidden", filename, "files rename failed")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
📒 Files selected for processing (1)
website/tests/test_main.py(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Run Tests
- GitHub Check: docker-test
🔇 Additional comments (1)
website/tests/test_main.py (1)
20-33: Import path fix is correct; refactoring suggestion is based on incorrect module analysis and is unnecessary.Switching from
.modelsto..modelsis the correct fix now that tests live inwebsite/tests/. However, the refactoring recommendation is based on a misunderstanding:ContentTypeandUserare already legitimately available fromwebsite.modelsbecausewebsite/models.pyimports them directly from Django at lines 16 and 18:from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentTypeSince
website/models.pyis a module file (not a package directory), these imports are automatically available for re-export to test code. The current import at lines 20–33 will work correctly as written—no refactoring needed.Likely an incorrect or invalid review comment.
Fixes: #4751
Description:
The GitHub Actions test workflow was failing due to Django being unable to import the tests module correctly.
Error message:
This PR moves the tests folder to the proper location within the app structure so Django can discover and execute tests as expected.
Also verified that the directory contains an init.py file to ensure it’s recognized as a valid module.
Passed all the test in my forked repo.

Summary by CodeRabbit