Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #20449 - Corrected test sensitivity to current working dir.

  • Loading branch information...
commit 022de7e1393541a3693919e1427d272df89f7f46 1 parent 7c56212
Tom Jaskowski authored May 19, 2013 carljm committed May 19, 2013

Showing 1 changed file with 17 additions and 3 deletions. Show diff stats Hide diff stats

  1. 20  tests/test_runner/test_discover_runner.py
20  tests/test_runner/test_discover_runner.py
... ...
@@ -1,3 +1,6 @@
  1
+from contextlib import contextmanager
  2
+import os
  3
+
1 4
 from django.test import TestCase
2 5
 from django.test.runner import DiscoverRunner
3 6
 
@@ -61,8 +64,19 @@ def test_pattern(self):
61 64
         self.assertEqual(count, 1)
62 65
 
63 66
     def test_file_path(self):
64  
-        count = DiscoverRunner().build_suite(
65  
-            ["test_discovery_sample/"],
66  
-        ).countTestCases()
  67
+        @contextmanager
  68
+        def change_cwd_to_tests():
  69
+            """Change CWD to tests directory (one level up from this file)"""
  70
+            current_dir = os.path.abspath(os.path.dirname(__file__))
  71
+            tests_dir = os.path.join(current_dir, '..')
  72
+            old_cwd = os.getcwd()
  73
+            os.chdir(tests_dir)
  74
+            yield
  75
+            os.chdir(old_cwd)
  76
+
  77
+        with change_cwd_to_tests():
  78
+            count = DiscoverRunner().build_suite(
  79
+                ["test_discovery_sample/"],
  80
+            ).countTestCases()
67 81
 
68 82
         self.assertEqual(count, 4)

0 notes on commit 022de7e

Please sign in to comment.
Something went wrong with that request. Please try again.