Ticket #22478: 0001-Fixed-22478.-Use-correct-module-variable-in-build_te.2.patch

File 0001-Fixed-22478.-Use-correct-module-variable-in-build_te.2.patch, 4.2 KB (added by Iacopo Spalletti, 11 years ago)

Code fix + Test

  • django/test/simple.py

    From 99364f8a58307ef3d9427befd1f4aeb0e24ed783 Mon Sep 17 00:00:00 2001
    From: Iacopo Spalletti <i.spalletti@nephila.it>
    Date: Mon, 21 Apr 2014 10:18:49 +0200
    Subject: [PATCH] Fixed #22478. Use correct module variable in build_tests for
     cycle.
    
    ---
     django/test/simple.py                                    |  2 +-
     tests/test_suite_override/sample_app/__init__.py         |  1 +
     tests/test_suite_override/sample_app/models.py           |  6 ++++++
     tests/test_suite_override/sample_app/tests/__init__.py   |  2 ++
     .../test_suite_override/sample_app/tests/test_module.py  | 11 +++++++++++
     tests/test_suite_override/tests.py                       | 16 +++++++++++++++-
     6 files changed, 36 insertions(+), 2 deletions(-)
     create mode 100644 tests/test_suite_override/sample_app/__init__.py
     create mode 100644 tests/test_suite_override/sample_app/models.py
     create mode 100644 tests/test_suite_override/sample_app/tests/__init__.py
     create mode 100644 tests/test_suite_override/sample_app/tests/test_module.py
    
    diff --git a/django/test/simple.py b/django/test/simple.py
    index 956294d..9eafaef 100644
    a b def build_test(label):  
    181181
    182182    TestClass = None
    183183    for module in test_modules:
    184         TestClass = getattr(models_module, parts[1], None)
     184        TestClass = getattr(module, parts[1], None)
    185185        if TestClass is not None:
    186186            break
    187187
  • new file tests/test_suite_override/sample_app/__init__.py

    diff --git a/tests/test_suite_override/sample_app/__init__.py b/tests/test_suite_override/sample_app/__init__.py
    new file mode 100644
    index 0000000..40a96af
    - +  
     1# -*- coding: utf-8 -*-
  • new file tests/test_suite_override/sample_app/models.py

    diff --git a/tests/test_suite_override/sample_app/models.py b/tests/test_suite_override/sample_app/models.py
    new file mode 100644
    index 0000000..59875f6
    - +  
     1# -*- coding: utf-8 -*-
     2from django.db import models
     3
     4
     5class MyModel(models.Model):
     6    title = models.CharField(max_length=200)
  • new file tests/test_suite_override/sample_app/tests/__init__.py

    diff --git a/tests/test_suite_override/sample_app/tests/__init__.py b/tests/test_suite_override/sample_app/tests/__init__.py
    new file mode 100644
    index 0000000..5df598c
    - +  
     1# -*- coding: utf-8 -*-
     2from .test_module import *
  • new file tests/test_suite_override/sample_app/tests/test_module.py

    diff --git a/tests/test_suite_override/sample_app/tests/test_module.py b/tests/test_suite_override/sample_app/tests/test_module.py
    new file mode 100644
    index 0000000..7e22265
    - +  
     1# -*- coding: utf-8 -*-
     2import unittest
     3from django.test.utils import IgnoreAllDeprecationWarningsMixin
     4
     5
     6class StubTest(IgnoreAllDeprecationWarningsMixin, unittest.TestCase):
     7
     8    def test_void(self):
     9        """
     10        This is actually a void test, just to check if it's loaded
     11        """
     12 No newline at end of file
  • tests/test_suite_override/tests.py

    diff --git a/tests/test_suite_override/tests.py b/tests/test_suite_override/tests.py
    index c485b80..9025f32 100644
    a b  
    11import unittest
    22
    33from django.apps import apps
    4 from django.test.utils import IgnoreAllDeprecationWarningsMixin
     4from django.test.utils import (IgnoreAllDeprecationWarningsMixin,
     5                               override_settings)
    56
    67
    78def suite():
    class SuiteOverrideTest(IgnoreAllDeprecationWarningsMixin, unittest.TestCase):  
    2425        suite = build_suite(app_config)
    2526        self.assertEqual(suite.countTestCases(), 1)
    2627
     28    @override_settings(INSTALLED_APPS=['test_suite_override.sample_app'])
     29    def test_build_tests(self):
     30        """
     31        This test is for #22478
     32
     33        when an application has test directory with tests organized in different
     34        modules inside the test directory, every application module must be
     35        checked for the passed test labels.
     36        """
     37        from django.test.simple import build_test
     38        suite = build_test("sample_app.StubTest")
     39        self.assertEqual(suite.countTestCases(), 1)
     40
    2741
    2842class SampleTests(unittest.TestCase):
    2943    """These tests should not be discovered, due to the custom suite."""
Back to Top