使用Python进行简单强大的无样板测试。还要为`pytest`标记的问题添加`python`标签。
考虑一个模块,该模块允许注册事件处理程序并在某种情况下发射它们: #myModule/myfile.py _EVENT_HANDLERS = [] def register_event_handler(处理程序): _EVENT_HANDLERS.APPEND(
如何运行具有适当依赖关系和模块路径的UV Pytest工具?
直接结构 项目根/ ├─— src/ File1.py ││├├-file2.py └ - 测试/ │├├─-test_file1.py ││├─-test_file2.py ├ - ─txt ├ - pyproject.toml 因此,基本上,在
,我有这样的课程: 类mytask(qtcore.qobject): def do(self): ... 类Manager(qtcore.qobject): def __init __(自我): super().__ init __() self.worker_exec ...
@pytest.mark.parametrize( ("get_nearby_sensors_mock", "get_nearby_sensors_errors"), [ (AsyncMock(side_effect=Exception), {CONF_BASE: CONF_UNKNOWN}), (AsyncMock(side_effect=PurpleAirError), {CONF_BASE: CONF_UNKNOWN}), (AsyncMock(side_effect=InvalidApiKeyError), {CONF_BASE: CONF_INVALID_API_KEY}), (AsyncMock(return_value=[]), {CONF_BASE: CONF_NO_SENSORS_FOUND}), # What do I do here? # (AsyncMock(api.sensors, "async_get_nearby_sensors")) does not work as api is not in scope? # (AsyncMock(side_effect=None), {}) does not call the default fixture? (AsyncMock(), {}), ], ) async def test_validate_coordinates( hass: HomeAssistant, mock_aiopurpleair, api, get_nearby_sensors_mock, get_nearby_sensors_errors, ) -> None: """Test validate_coordinates errors.""" with ( patch.object(api, "async_check_api_key"), patch.object(api.sensors, "async_get_nearby_sensors", get_nearby_sensors_mock), ): result: ConfigValidation = await ConfigValidation.async_validate_coordinates( hass, TEST_API_KEY, TEST_LATITUDE, TEST_LONGITUDE, TEST_RADIUS ) assert result.errors == get_nearby_sensors_errors if result.errors == {}: assert result.data is not None else: assert result.data is None
here是一个简单的测试文件: #test_single.py def test_addition(): “两个加两个仍然四个” 断言2 + 2 == 4 def test_addition2(): “一个加一个是两个” 断言1 + 1 == ...
设置),我想在与源代码的同一文件中进行单位测试,而将
我需要从.txt,Split()向下提取时间戳记,然后将时间打印到一个小时,然后打印小时(排序)和发生。到目前为止,我已经做了几种方法,而pytest永远不会匹配(但看起来...
I使用PYTEST进行测试,该测试又运行了几个芹菜任务。但是,当我使用 mprof run-include-children py.test test.py 我无法跟踪每个芹菜任务所消耗的内存...