小编hoe*_*ing的帖子

如何在python中获取log10值的倒数?

y=np.log10(train_set["SalePrice"])
Run Code Online (Sandbox Code Playgroud)

我如何找到这个的反面??我希望它返回到原始值而不是缩放值

python inverse

4
推荐指数
2
解决办法
2万
查看次数

找不到满足选择要求的版本

我目前正在尝试安装一个需求,它告诉我当我尝试将它们注释掉时找不到它,它会发生在其他人身上。

我刚刚部署了一个Ubuntu 18.04服务器。通过以下命令创建虚拟环境,python3 -m venv --system-site-packages env但每次我尝试运行pip install -r requirements.txt它都会失败

Collecting apparmor==2.12 (from -r requirements.txt (line 1))
  Could not find a version that satisfies the requirement apparmor==2.12 (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for apparmor==2.12 (from -r requirements.txt (line 1))
Run Code Online (Sandbox Code Playgroud)

如果我尝试安装说它pip install apparmor告诉我

Collecting apparmor
  Could not find a version that satisfies the requirement apparmor (from versions: )
No matching distribution found for apparmor
Run Code Online (Sandbox Code Playgroud)

但是如果我注释掉 apparmor …

python ubuntu pip virtualenv ubuntu-18.04

4
推荐指数
2
解决办法
6003
查看次数

如何确保仅在 pytest 中明确询问时才运行带有标记的测试?

我有一些测试我用适当的标记标记。如果我运行 pytest,默认情况下它们会运行,但我想默认跳过它们。我知道的唯一选择是在 pytest 调用时明确说“不标记”,但我不希望它们默认运行,除非在命令行明确询问标记。

python pytest

4
推荐指数
2
解决办法
970
查看次数

如何在执行 pytest 测试用例时在命令提示符中使用通配符

我在 Pycharm 中有以下项目结构。

项目文件夹: PythonTutorial

包: pytestpackage

Python 文件: test_conftest_demo1.py、test_conftest_demo2.py

我正在尝试从命令提示符下使用 pytest 使用以下命令运行具有几乎相似名称的上述 2 个 python 文件。但我面临以下问题。请帮助我。

注意:我使用的是 windows 10 操作系统。

使用的命令: py.test -s -v test_conftest_demo*.py

在此处输入图片说明

python pytest pycharm

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

pytest-django:这是使用参数测试视图的正确方法吗?

假设我正在Django应用程序中测试RSS feed视图,这是我应该怎么做的吗?

def test_some_view(...):
    ...
    requested_url = reverse("personal_feed", args=[some_profile.auth_token])
    resp = client.get(requested_url, follow=True)
    ...
    assert dummy_object.title in str(resp.content)
Run Code Online (Sandbox Code Playgroud)
  1. reverse-ing然后将其传递client.get()给正确的测试方法?我认为这比以前简单地.get()设置URL 更干燥,而且更适合未来使用。

  2. 我应该断言这dummy_object就是这种回应吗?

  3. 我在这里使用str响应对象的表示形式进行测试。与使用时相比,selenium什么时候是个好习惯?我知道,例如,可以更轻松地验证obj或属性(如dummy_object.title)是否封装在H1标签中。在另一方面,如果我不关心如何与obj表示,它的速度更快做像上面。

python django django-testing pytest pytest-django

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

如何在 pytest 中将自定义部分添加到终端报告

pytest中,当测试用例失败时,报告中会显示以下类别:

  • 失败详情
  • 捕获的标准输出调用
  • 捕获的 stderr 调用
  • 捕获的调用日志

py测试报告

我想添加一些额外的自定义部分(我有一个并行运行的服务器,并且希望在专用部分中显示该服务器记录的信息)。

我怎样才能做到这一点(如果可能的话)?

谢谢


笔记

我目前在源代码中找到了以下内容,但不知道这是否是正确的方法

节点.py

class Item(Node):
    ...
    def add_report_section(self, when, key, content):
        """
        Adds a new report section, similar to what's done internally
        to add stdout and stderr captured output:: 
        ...
        """
Run Code Online (Sandbox Code Playgroud)

报告.py

class BaseReport:
    ...

    @property
    def caplog(self):
        """Return captured log lines, if log capturing is enabled

        .. versionadded:: 3.5
        """
        return "\n".join(
            content for (prefix, content) in self.get_sections("Captured log")
        )
Run Code Online (Sandbox Code Playgroud)

python pytest

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

InsecureRequestWarning + pytest

我仍然有关于 pytest 摘要的 SSL 警告。
Python 2.7.5
requests==2.22.0
urllib3==1.25.3
pytest version 4.3.1

这是代码:

import requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

def test_x():
  response = requests.get("https:// ...",
                          verify=False)
  print response.text
Run Code Online (Sandbox Code Playgroud)

输出pytest mytest.py

....    
==================================================== warnings summary ====================================================
prova.py::test_x
  /usr/lib/python2.7/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
    InsecureRequestWarning)

-- Docs: https://docs.pytest.org/en/latest/warnings.html
========================================== 1 passed, 1 warnings in 0.30 seconds ==========================================
Run Code Online (Sandbox Code Playgroud)

如何从 pytest 中删除 SSL 警告?

python ssl pytest

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

如何在有角度的Web Worker内导入节点模块?

我尝试在Angular 8 Web Worker内导入节点模块,但出现编译错误“找不到模块”。有人知道如何解决吗?

我在的电子项目中使用创建了一个新工作人员ng generate web-worker app,如上述ng文档中所述。

一切正常,直到我添加一些导入,例如pathfs-extra

/// <reference lib="webworker" />    
import * as path from 'path';

addEventListener('message', ({ data }) => {    
  console.log(path.resolve('/'))
  const response = `worker response to ${data}`;
  postMessage(response);
});
Run Code Online (Sandbox Code Playgroud)

这种导入在任何其他ts组件中都可以正常工作,但是在Web Worker中,我收到此消息的编译错误,例如

Error: app/app.worker.ts:3:23 - error TS2307: Cannot find module 'path'.
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?也许我需要在生成一些其他参数tsconfig.worker.json

重现该错误,请运行:

$ git clone https://github.com/hoefling/stackoverflow-57774039
$ cd stackoverflow-57774039
$ yarn build
Run Code Online (Sandbox Code Playgroud)

或在Travis上查看项目的构建日志

注意:

1)我只发现是一个类似的问题,但答案仅处理自定义模块。

2)我使用 …

web-worker node.js typescript angular angular8

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

PyTest:在运行时动态生成测试名称

当我使用夹具运行测试时,我想在运行时动态命名测试@pytest.mark.parametrize("value",values_list)。例如:

values_list=['apple','tomatoes','potatoes']

@pytest.mark.parametrize("value",values_list)
def test_xxx(self,value):
    assert value==value
Run Code Online (Sandbox Code Playgroud)

我想看到的最终结果是 3 个测试,名称如下:

测试苹果

测试番茄

测试土豆

我尝试查看 pytest 文档,但我还没有发现任何可能阐明这个问题的内容。

python pytest python-3.x parametrized-testing

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

获取测试套件中每个测试的 SQL 查询计数概览

我有一个大型 Django 应用程序,其中包含大量需要 SQL 查询优化的测试。

我正在使用 pytest-django 来运行我的测试。

我不想单独添加assertNumQueriesdjango-assert-num-queries针对每个测试,而是生成有关所有测试中的每个测试触发了多少 SQL 查询的概述,以了解哪些代码需要最优化,如下所示:

test                         | number of queries
------------------------------------------------
test_a.py::test_my_function1 |  5
test_a.py::test_my_function3 |  2
test_a.py::test_my_function5 |  7
Run Code Online (Sandbox Code Playgroud)

是否可以在 conftest.py 中配置一个 pytest 钩子,它计算每个 (DB) 测试的 SQL 查询数量并在结果中显示它们 - 无需修改我的测试源(如添加装饰器)?

我天真的方法是使用这些钩子,并以某种方式在每次测试前后访问数据库连接:

def pytest_runtest_call(item):
    pass

def pytest_runtest_teardown(item, nextitem):
    return True

Run Code Online (Sandbox Code Playgroud)

python django pytest pytest-django

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