我试图让我的单元测试显示在 VSCode 的测试资源管理器中,但它似乎不起作用。测试发现不会因输出中出现任何错误而失败,但也不会显示我的任何测试。
这是我正在使用的存储库,您可以在那里看到文件结构。
这可能与我使用诗歌来管理我的虚拟环境有任何关系,也可能没有任何关系,尽管我确信 python 解释器设置正确。pytest我可以通过运行或在我的基本目录中手动让我的测试完美运行poetry run pytest。__init__.py我的测试目录中确实有一个空目录。另外值得注意的是,我在 WSL 2 上的 Ubuntu 中运行。
我通过以下过程设置了这个环境:
pip install poetrypoetry install这是我的工作区设置.json:
{
"restructuredtext.confPath": "${workspaceFolder}/docs/source",
"python.testing.pytestEnabled": true,
}
Run Code Online (Sandbox Code Playgroud)
以下是我尝试刷新测试时显示的输出:
~/.cache/pypoetry/virtualenvs/monaco-bfS1OgpY-py3.9/bin/python ~/.vscode-server/extensions/ms-python.python-2021.11.1422169775/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/coding/monaco -s …Run Code Online (Sandbox Code Playgroud) 我正在尝试扩展 scipy.stats.rv_discrete 以为用户提供一些简单的分布。例如,在最简单的情况下,他们可能想要具有恒定输出的分布。这是我的代码:
from scipy.stats._distn_infrastructure import rv_sample
class const(rv_sample): # a distribution with probability 1 for a single val
def __init__(self, val, *args, **kwds):
super(const, self).__init__(values=(val, 1), *args, **kwds)
Run Code Online (Sandbox Code Playgroud)
但是,这不会产生与内置随机变量分布相同类型的对象,这会扰乱我想要对分布执行的一些操作。将其与泊松分布进行比较:
from scipy.stats import poisson
import inspect
print('\nThese should both contain rv_discrete:')
print('1: ', inspect.getmro(poisson.__class__))
print('2: ', inspect.getmro(const.__class__))
print('\nThese should both be rv_frozen:')
print('1: ', inspect.getmro(poisson(5).__class__))
print('2: ', inspect.getmro(const(5).__class__))
Run Code Online (Sandbox Code Playgroud)
输出:
These should both contain rv_discrete:
1: (<class 'scipy.stats._discrete_distns.poisson_gen'>, <class 'scipy.stats._distn_infrastructure.rv_discrete'>, <class 'scipy.stats._distn_infrastructure.rv_generic'>, <class 'object'>)
2: (<class 'type'>, <class 'object'>)
These should …Run Code Online (Sandbox Code Playgroud)