Skip to content

Refactor test files to use pytest fixtures for improved maintainability#2

Draft
Copilot wants to merge 152 commits into
masterfrom
copilot/fix-8c5226a5-621c-4720-b0aa-e9cc23099031
Draft

Refactor test files to use pytest fixtures for improved maintainability#2
Copilot wants to merge 152 commits into
masterfrom
copilot/fix-8c5226a5-621c-4720-b0aa-e9cc23099031

Conversation

Copilot AI commented May 25, 2025

Copy link
Copy Markdown

Summary

This PR refactors several test files to use pytest fixtures instead of setUp methods and repetitive object creation. This improves test maintainability, readability, and reusability while preserving compatibility with Django's test runner.

Changes

  • Added pytest configuration (pytest.ini)
  • Created module-specific fixture collections in conftest.py files for:
    • qatrack/attachments/tests
    • qatrack/qa/tests
    • qatrack/reports/tests
    • qatrack/notifications/qccompleted
    • qatrack/notifications/service_log_scheduling
  • Refactored test classes to use fixtures instead of setUp methods
  • Added proper docstrings to test methods
  • Maintained backward compatibility with Django's TestCase

Benefits

  1. Improved Maintainability: Common test setup code is now shared via fixtures rather than duplicated across test methods.
  2. Better Readability: Test methods now focus on assertions rather than setup, making their intent clearer.
  3. Enhanced Reusability: Fixtures can be reused across different test modules.
  4. Dual Compatibility: Tests work with both Django's test runner and pytest.
  5. Easier Test Modifications: Changes to test objects only need to be made in one place.

Example

Before:

def test_something(self):
    site = USite.objects.create(name="site")
    unit = utils.create_unit(site=site)
    utc = utils.create_unit_test_collection(unit=unit)
    # Test logic here

After:

def test_something(self, site, unit):
    """Test description here."""
    utc = utils.create_unit_test_collection(unit=unit)
    # Test logic here

Related Files

  • qatrack/attachments/tests/test_models.py
  • qatrack/qa/tests/test_utils.py
  • qatrack/qa/tests/test_tags.py
  • qatrack/reports/tests/test_qc.py
  • And newly created conftest.py files in various directories

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits May 25, 2025 18:37
Co-authored-by: crcrewso <6089951+crcrewso@users.noreply.github.com>
Co-authored-by: crcrewso <6089951+crcrewso@users.noreply.github.com>
Co-authored-by: crcrewso <6089951+crcrewso@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor tests with multiple asserts to use pytest fixtures Refactor test files to use pytest fixtures for improved maintainability May 25, 2025
Copilot AI requested a review from crcrewso May 25, 2025 18:44
crcrewso and others added 20 commits June 12, 2026 11:22
Fixes `BaseReport.make_url(...)` to handle the case where both domain ends with "/" and url ends with "/". Previous to this fix, links could be generated with "//" in them, rendering them unusable.
Some selenium tests not working
admin page is a mess
Updated to re_path, prep for django 4+

default_app_configuration no longer needed

default_app_config no longer needed 2

default auto field change for db models

internalizing admin_views for maintanability

internalize form_utils

missed updates

missed find_elements function change in prev commit
…inheritance, add proper URL patterns, add permission checks, create template, and add tests
…precated django-admin-views package which has been replaced with class-based views. Tests are kept commented for reference during migration.
nsmela and others added 24 commits June 12, 2026 11:33
…cated stage names (commit, push) which will be removed in a future version. Hint: often `pre-commit autoupdate --repo https://github.com/pre-commit/pre-commit-hooks` will fix this.  if it does not -- consider reporting an issue to that repo.
Fixed regression in views:
Admin -> QC -> Statuses (admin/qa/testinstancestatus/) 
Admin -> Service Log -> Service Event Statuses (admin/service_log/serviceeventstatus/)
@crcrewso

Copy link
Copy Markdown
Owner

@copilot

This was great work, but, could you rebase it off of the develop branch

# Conflicts:
#	.gitignore
#	qatrack/qa/tests/test_tags.py
#	qatrack/reports/tests/test_qc.py

Copilot AI commented Jun 15, 2026

Copy link
Copy Markdown
Author

@copilot

This was great work, but, could you rebase it off of the develop branch

Done — I've merged the develop branch into this PR branch (commit ab3868f3), resolving the three conflicts in .gitignore, qatrack/qa/tests/test_tags.py, and qatrack/reports/tests/test_qc.py. The PR now includes all latest changes from develop.

Comment thread qatrack/settings.py
SECRET_KEY = secrets.token_urlsafe(64)
os.makedirs(os.path.dirname(SECRET_FILEPATH), exist_ok=True)
with open(SECRET_FILEPATH, 'w') as f:
f.write(SECRET_KEY)
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.

6 participants