Python Unitest模块与打字不兼容?

发布于 2025-01-21 17:11:42 字数 518 浏览 1 评论 0原文

与设置一个简单的测试套件并存,我有src/main.py和src/tests.py。我遇到了这个错误。

  File "main.py", line 26
    def error(msg: str) -> int:
                 ^
SyntaxError: invalid syntax

我的代码

from main import error
from typing import *
import unittest


class TestMainFunctions(unittest.TestCase):

    def test_error():
        result = error("e")
        self.assertEqual(result, 0)

unittest.main()

有什么方法可以解决此问题吗?运行main.py时,error()函数正常工作。 Untiment模块是否与键入不兼容?如果是这样,我该如何解决?

Tying to set up a simple test suite, I have src/main.py and src/tests.py. I am getting this error.

  File "main.py", line 26
    def error(msg: str) -> int:
                 ^
SyntaxError: invalid syntax

My code is

from main import error
from typing import *
import unittest


class TestMainFunctions(unittest.TestCase):

    def test_error():
        result = error("e")
        self.assertEqual(result, 0)

unittest.main()

Is there any way to fix this? The error() function works fine when running main.py. Is the unittest module just not compatible with typing? If so, how do I get around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文