小编use*_*643的帖子

如何使用 pytest Monkeypatch 来修补类

我想使用 [pytest Monkeypatch][1] 来模拟导入到单独模块中的类。这实际上可能吗?如果可能的话,如何做到这一点?我似乎还没有看到这种具体情况的例子。假设您有一个应用程序并在 Something.py 中导入了 A 类

from something import A #Class is imported

class B :
  def __init__(self) :
   self.instance = A() #class instance is created

  def f(self, value) :
    return self.instance.g(value)
Run Code Online (Sandbox Code Playgroud)

在我的 test.py 中我想在 B 中模拟 A

from something import B

#this is where I would mock A such that
def mock_A :
  def g(self, value) :
    return 2*value

#Then I would call B
c = B()
print(c.g(2)) #would be 4

I see how monkeypatch can be …
Run Code Online (Sandbox Code Playgroud)

python monkeypatching class pytest

11
推荐指数
1
解决办法
1万
查看次数

stanford-corenlp 中的默认线程数是多少

stanford-corenlp 中的默认线程数是多少?具体来说,是命名实体提取器,然后是信息提取器。另外,我希望两者都使用单个线程进行调试,我该如何设置?

谢谢!

multithreading stanford-nlp

4
推荐指数
1
解决办法
1961
查看次数

elasticsearch tf-idf并忽略搜索中的字段长度范数

我想在elasticsearch中执行搜索,忽略tf-idf搜索中的字段规范.您可以通过设置索引映射忽略字段规范来实现此目的.然而,似乎这是通过更改索引来实现的,我只想修改搜索(我需要其他类型搜索的规范).完成此任务的最佳方法是什么?我使用elasticsearch.js作为elasticsearch的接口.

elasticsearch

3
推荐指数
1
解决办法
997
查看次数