Skip to content

[REFACTOR] Refactor Views Tests Setup to Use setUpTestData for Improved Performance #399

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
Aug 1, 2025

Conversation

Itz-Agasta
Copy link
Contributor

Fixes #369

This PR refactors the TestViews class in test_views.py to use setUpTestData instead of setUp, significantly improving test performance by reducing redundant database operations.

Changes Made

  • Refactored test data setup: Replaced setUp method with @classmethod setUpTestData(cls)
  • Optimized database operations: Test data is now created once per test class instead of before every individual test
  • Maintained test isolation: Ensured all tests continue to work correctly with shared test data
  • Code quality improvements: Fixed linting issues and ensured full CI/CD compliance

Performance Benefits

Metric Before (setUp) After (setUpTestData) Improvement
Test execution time ~0.30s ~0.25s 17% faster
Total runtime ~1.8s ~1.7s 6% faster
Database operations 195 objects (15×13) 15 objects (1×15) 92% reduction

Files Changed

  • test_views.py

@Itz-Agasta
Copy link
Contributor Author

Itz-Agasta commented Aug 1, 2025

Hi @Lorygold ,

PR #389 had some merge conflicts, which I’ve resolved. As you mentioned, the related issue #369 for this PR is specifically focused on refactoring the Views tests. Since other methods are being handled in separate issues and PRs, i removed the file changes by me in alart/ this time.

That’s why I’ve opened this new PR.

Also, I ran the linters and formatters manually, and removed self.client in the function as you had pointed out in PR #389. Let me know if anything else needs to be adjusted!

@Lorygold Lorygold self-requested a review August 1, 2025 08:09
@Lorygold
Copy link
Collaborator

Lorygold commented Aug 1, 2025

Great @Itz-Agasta, I'll merge it!

@Lorygold Lorygold merged commit 8a5b8f1 into certego:develop Aug 1, 2025
2 checks passed
@Itz-Agasta Itz-Agasta deleted the test_fixs branch August 1, 2025 08:23
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.

[REFACTOR] <Views Tests>: Refactor Views Tests Setup to Use setUpTestData for Improved Performance
2 participants