Python Pytest正在抛出警告字符串>;:1:弃用警告:转义序列无效\s

Python Pytest正在抛出警告字符串>;:1:弃用警告:转义序列无效\s,python,unit-testing,pytest,Python,Unit Testing,Pytest,当我执行pytest单元测试时,我得到以下警告 qualys/tests/test_scan.py::TestQualysScan::test_w string>:1: 弃用警告:无效的转义序列\s 我已经在我的代码中搜索了所有'\s',但在原始字符串(r'…')中找到的很少,所以这应该不是问题 我也不明白中1的含义 字符串>:1: 应该是字符串还是行号 你有什么建议如何修复它或如何获得确切的行号 class TestQualysScan: def test_w(self, mock_m

当我执行pytest单元测试时,我得到以下警告

qualys/tests/test_scan.py::TestQualysScan::test_w string>:1: 弃用警告:无效的转义序列\s

我已经在我的代码中搜索了所有
'\s'
,但在原始字符串(
r'…'
)中找到的很少,所以这应该不是问题

我也不明白中
1
的含义

字符串>:1:

应该是字符串还是行号

你有什么建议如何修复它或如何获得确切的行号

class TestQualysScan:
    def test_w(self, mock_mysqlApi, mock_qualysRequest):
        test_scan = QualysScan(mock_qualysRequest(), 'EMEA', [mock_qualysServer], 'test_scan',
                               mysqlApi=mock_mysqlApi(ops_server_table_sample[0]))
        assert True
和固定装置:

@pytest.fixture
def mock_mysqlApi():
    def _mock_mysqlApi_factory (db_entry_dict):
        mock_mysqlApi = MagicMock(spec=MysqlApi)
        mock_cursor = MagicMock(spec=DictCursorLogged)
        mock_mysqlApi.get_cursor().__enter__.return_value = mock_cursor
        mock_cursor.fetchone.return_value = db_entry_dict
        mock_cursor.fetchall.return_value = db_entry_dict

        return mock_mysqlApi
    return _mock_mysqlApi_factory


我已将pytest配置为将警告作为错误(-W)处理,因此它报告了带有错误的精确行,并且我能够识别问题:

 pytest.py -srapP -W error::DeprecationWarning -v

请将
TestQualyScan
中的相关代码添加到您的问题中。只是一个猜测:您是否在Windows上运行代码,当前目录以s开头,如
C:\Users\sakalos
?@roland-否是Jsakalos帮助我修复了相同的问题,源于导入的代码。路径为“c:\dblabla…”只需将其更改为c:\\dblabla
 pytest.py -srapP -W error::DeprecationWarning -v