Skip to content

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

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-8c5226a5-621c-4720-b0aa-e9cc23099031
Draft

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

Conversation

Copy link

Copilot AI commented May 25, 2025

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

Comments