小编Dan*_*ler的帖子

Pytest 跳过测试说“未安装 asyncio”

测试以下代码时

@pytest.mark.asynico
async def test_handle_DATA(mocker):
    handle_mock = mocker.MagicMock()
    envelope_mock = mocker.MagicMock(mail_from="Test@From", rcpt_tos=["Test@To"], content=b"TestContent")

    result = SendToDictHandler.handle_DATA(handle_mock, "TestServer", "TestSession", envelope_mock)

    assert result == "250 Message accepted for delivery"
    assert email_core.testing_emails_dict == {
        "Test@To": {
            "from": "Test@From",
            "to": ["Test@To"],
            "msg": "TestContent",
        }
    }
Run Code Online (Sandbox Code Playgroud)

pytest -vvv在项目环境中运行时收到的警告:

PytestWarning: Coroutine functions are not natively supported and have been skipped.
You need to install a suitable plugin for your async framework, for example:
 - pytest-asyncio
 - pytest-trio
 - pytest-tornasync
warnings.warn(PytestWarning(msg.format(pyfuncitem.nodeid)))
Run Code Online (Sandbox Code Playgroud)

我确实pytest-asyncio安装了。我通过pytest --trace-config …

python pytest python-asyncio pytest-asyncio

9
推荐指数
1
解决办法
5748
查看次数

码头工人和剧作家

我需要在 docker 内部安装 playwright。这是我的 dockerfile。

FROM python:3.9

EXPOSE 8000

WORKDIR /fastanalytics

COPY /requirements.txt /fastanalytics/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /fastanalytics/requirements.txt

RUN playwright install
RUN playwright install-deps
RUN apt-get update && apt-get upgrade -y

Run Code Online (Sandbox Code Playgroud)

但是当我安装时出现以下错误。我尝试安装错误消息中的所有内容,但没有帮助。

E: Package 'ttf-ubuntu-font-family' has no installation candidate
E: Unable to locate package libenchant1c2a
E: Unable to locate package libicu66
E: Package 'libjpeg-turbo8' has no installation candidate
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

python docker

6
推荐指数
2
解决办法
7536
查看次数

将参数传递给 pytest 夹具进行拆卸

问题: 清理从测试中创建的测试工件。在下面的情况下,如何使用 pytest 固定装置从数据库中删除在测试期间创建的单行?(并不是每次运行后都应该从表中删除所有内容。否则可以使用删除所有行或删除表)。创建的行的行标识符在测试期间保存在函数变量中。

是否可以将测试期间创建的变量作为参数传递到 pytest 中的夹具中?无论测试是通过失败还是成功完成,夹具都需要始终运行。在运行测试之前不会知道行标识符。

用夹具说明的问题

@pytest.fixture()
def clean_up_db_row(row_id):
    yield
    delete_from_db(self.row_id). # code to delete the row based on the id


def test_something_added_to_database(clean_up_db_row):
    row_id = create_db_row()  # function under test
    ...
    assert row_id in db  # test that information added to the database

    # the clean_up_db_row fixture will always run but how will it know about the id variable defined in the function?

Run Code Online (Sandbox Code Playgroud)

如果断言在测试中途失败,则在将清理工作拖到最后时,在测试期间添加的行不会被删除。因为测试停止执行。

问题的示例是没有 pytest 固定装置:

def clean_up_db_row(row_id):
    yield
    delete_from_db(row_id). # code to delete the row based …
Run Code Online (Sandbox Code Playgroud)

fixtures pytest

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