Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django单元测试在项目范围内失败,但在应用程序范围内通过_Django_Unit Testing_Python Unittest_Django Unittest - Fatal编程技术网

Django单元测试在项目范围内失败,但在应用程序范围内通过

Django单元测试在项目范围内失败,但在应用程序范围内通过,django,unit-testing,python-unittest,django-unittest,Django,Unit Testing,Python Unittest,Django Unittest,我在Ubuntu12.10上使用Django1.4和Python2.7 我有一个项目,有几个应用程序和几十个单元测试。我们最近在使用@override\u设置时遇到了一个小问题 下面是一些代码: @override_settings(MEDIA_URL='/test/media/') def test_get_content_dict(self): self.assertEqual( self.offer.get_content_dict(

我在Ubuntu12.10上使用Django1.4和Python2.7

我有一个项目,有几个应用程序和几十个单元测试。我们最近在使用
@override\u设置时遇到了一个小问题

下面是一些代码:

@override_settings(MEDIA_URL='/test/media/')
    def test_get_content_dict(self):
        self.assertEqual(
                self.offer.get_content_dict(),
                { 'some stuff': some stuff }
当在应用程序级别运行测试时,一切都通过了

python manage.py test my_app --settings=proton.settings.test
但当我们在项目级别运行时,它失败了

python manage.py test --settings=proton.settings.test
由于使用
/test/media
某些东西
而失败,但是模型方法
提供了。使用
/media
获取
,这是我们实际的
媒体URL

我们可以在
设置/test.py
文件中更改
媒体URL
,但这需要所有测试都使用
/test/MEDIA
(这可能是个好主意)

显然,问题出在Django的
core.files.storage.FileSystemStorage.\uuu init\uuuu()
-它在测试套件的前面设置了
base\u url
,但在每次测试后都不会重新实例化对象(出于明显的原因),因此
@override\u设置
实际上没有任何作用


这是一个bug还是按预期工作?除了通过将
设置/test.py
中的
媒体URL
常量设置为
/test/media
来强制所有单元测试使用
/test/media
,还有什么关于优雅解决方案的建议吗?

我同意,让所有测试代码针对
/test/media
运行可能是个好主意。否则,可能
get\u content\u dict
可以接受
base\u url
kwarg?@dokkaebi我们决定更改
settings/test.py
文件中的
MEDIA\u url=/test/MEDIA
,并强制所有测试使用该值。虽然这是一项简单的工作,但我觉得没有必要。毕竟,
@override\u settings
如果不能真正覆盖设置,有什么好处?