当测试失败时,会有一个输出指示测试的上下文,例如
=================================== FAILURES ===================================
______________________________ Test.test_sum_even ______________________________
numbers = [2, 4, 6]
@staticmethod
def test_sum_even(numbers):
assert sum(numbers) % 2 == 0
> assert False
E assert False
test_preprocessing.py:52: AssertionError
Run Code Online (Sandbox Code Playgroud)
如果我也希望通过测试得到同样的结果怎么办?这样我就可以快速检查传递给测试的参数是否正确?
我试着命令行选项行--full-trace,-l,--tb long,和-rpP,但他们没有工作。
任何的想法?
我在不断更新显示的图形时遇到问题。有人可以帮我吗?
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import numpy as np
import bokeh
from bokeh.io import push_notebook, show, output_notebook
from bokeh import layouts
from bokeh.plotting import figure
output_notebook()
# In[2]:
def to_data_source(y):
y = np.array(y)
x = np.arange(y.size)
return bokeh.models.ColumnDataSource({
'x': x,
'y': y
})
# In[3]:
# this will plot an empty figure
vis = figure()
handle = show(vis, notebook_handle=True)
# In[4]:
# this will plot on the empty figure
line = vis.line()
line.data_source = to_data_source(np.random.randn(30))
push_notebook(handle=handle)
# …Run Code Online (Sandbox Code Playgroud) For simple list creations, it is recommended to use list comprehension. However, when it comes to more complicated scenarios, spanning the list creation across multiple lines is more advisable.
e.g. for a simple task
[x for x in range(10)]
Run Code Online (Sandbox Code Playgroud)
e.g. for a more complicated task
result = []
for x in complicated:
if y is complex:
for z in intricate_stuff:
result.append(convoluted(z))
Run Code Online (Sandbox Code Playgroud)
(I probably would still use a multi-line list comprehension for the above example, but anyways you get the idea.) …