当我并行运行测试时,我会遇到随机失败,因为一个测试干扰了另一测试的缓存。
我可以解决这个问题
@override_settings(
CACHES={
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"LOCATION": "[random_string]",
}
},
)
Run Code Online (Sandbox Code Playgroud)
实际上,为了使其更小,我创建了一个@isolate_cache装饰器,它是override_settings.
但我仍然需要去装饰大量的测试用例。这很容易出错,因为正如我所说,失败是随机的。我可能会运行测试套件 100 次而没有错误,并认为一切正常,但我仍然可能忘记装饰测试用例,并且在某些时候它会随机失败。
我还考虑过创建自己的TestCase子类并仅将其用于我的所有测试用例。这提出了一个类似的问题:在某些时候有人会出于django.test.TestCase习惯继承,并且它可能不会在很长一段时间内失败。此外,我的一些测试继承自rest_framework.test.APITestCase(或其他类),因此没有单个测试用例子类。
有什么方法可以告诉 Django 在缓存的隔离部分中一劳永逸地运行每个测试用例吗?
如果我想在带有可见(非无头)浏览器的 Docker 容器中运行 Selenium 测试,我有哪些选择?
selenium selenium-webdriver docker dockerfile docker-compose
我已经能够找到的唯一的文档.backup和.dump是所示的.help:
.backup ?DB? FILE Backup DB (default "main") to FILE
.dump ?TABLE? ... Dump the database in an SQL text format
If TABLE specified, only dump tables matching
LIKE pattern TABLE.
Run Code Online (Sandbox Code Playgroud)
最大的问题是:在复制/转储之前,这两个命令是否都锁定了数据库?备份是否一致?
这个答案有一些关于 的信息.backup,但是否有任何权威文档?(还有呢.dump?)我在 SQLite 的文档中唯一能找到的是“在线备份 API ”,但我对 API 不感兴趣,我只想备份数据库。
我的服务器运行Django + Gunicorn + nginx.
我添加了SSL证书并配置了nginx以将http重定向到https.当收到https请求时,nginx将其作为http传递给Gunicorn.
我的程序有时返回HttpResponseRedirect,浏览器获得重定向响应并重新请求为http,因此nginx重定向到https.
我怎么能避免这个?如何配置服务器以使第一个重定向直接指向https URL?
我是一个 Jest/React 初学者。在玩笑中,it我需要等到所有承诺都已执行后再实际检查。
我的代码类似于:
export class MyComponent extends Component {
constructor(props) {
super(props);
this.state = { /* Some state */ };
}
componentDidMount() {
fetch(some_url)
.then(response => response.json())
.then(json => this.setState(some_state);
}
render() {
// Do some rendering based on the state
}
}
Run Code Online (Sandbox Code Playgroud)
当组件被挂载时,render()运行两次:一次在构造函数运行之后,一次在fetch()(in componentDidMount()) 完成并且链式承诺完成执行之后)。
我的测试代码类似于:
describe('MyComponent', () => {
fetchMock.get('*', some_response);
it('renders something', () => {
let wrapper = mount(<MyComponent />);
expect(wrapper.find(...)).to.have.something();
};
}
Run Code Online (Sandbox Code Playgroud)
无论我从什么返回it,它都会在第一次render()执行之后但在第二次执行之前运行。例如,如果我 return …
我需要分析泰米尔文本文件(utf-8编码).我在IDLE接口上使用了nltk Python包.当我尝试读取界面上的文本文件时,这是我得到的错误.我该如何避免这种情况?
corpus = open('C:\\Users\\Customer\\Desktop\\DISSERTATION\\ettuthokai.txt').read()
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
corpus = open('C:\\Users\\Customer\\Desktop\\DISSERTATION\\ettuthokai.txt').read()
File "C:\Users\Customer\AppData\Local\Programs\Python\Python35-32\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 33: character maps to <undefined>
Run Code Online (Sandbox Code Playgroud) 我已经配置了python-mode来手动检查.所以我输入:PyLint并检查我的代码,显示"QuickFix"窗口和侧面的一些标记.我可以随后通过:only在其他窗口中输入来关闭QuickFix窗口,但是如何清除侧标记?
在Django 1.8时,ChoiceField的choices参数可以接受一个可调用的:
def get_choices():
return [(1, "one"), (2, "two")]
class MyForm(forms.Form):
my_choice_field = forms.ChoiceField(choices=get_choices)
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,get_choices()始终返回相同的选项.但是,能够分配一个callable choices并没有多大意义,除非callable每次调用时都知道像对象id这样的东西.我怎么能把这样的东西传递给它呢?
例子:
import pandas as pd
import numpy as np
rng = pd.date_range("2000-01-01", periods=12, freq="T")
ts = pd.Series(np.arange(12), index=rng)
ts["2000-01-01 00:02"] = np.nan
ts
Run Code Online (Sandbox Code Playgroud)
2000-01-01 00:00:00 0.0
2000-01-01 00:01:00 1.0
2000-01-01 00:02:00 NaN
2000-01-01 00:03:00 3.0
2000-01-01 00:04:00 4.0
2000-01-01 00:05:00 5.0
2000-01-01 00:06:00 6.0
2000-01-01 00:07:00 7.0
2000-01-01 00:08:00 8.0
2000-01-01 00:09:00 9.0
2000-01-01 00:10:00 10.0
2000-01-01 00:11:00 11.0
Freq: T, dtype: float64
Run Code Online (Sandbox Code Playgroud)
ts.resample("5min").sum()
Run Code Online (Sandbox Code Playgroud)
2000-01-01 00:00:00 5.0
2000-01-01 00:05:00 30.0
2000-01-01 00:10:00 30.0
Freq: 5T, dtype: float64
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,它提取区间 00:00-00:05 的总和,就好像缺失值为零一样。我想要的是它在 …