单元测试练习有问题,找不到模块

Problem with Unit Testing Exercise, module not found

我被困在一个练习中。这些是我得到的文件:

自述文件:

在你开始之前,确保在你的终端中运行这个命令来安装pytest:

pip install -U pytest

然后,到运行 pytest,输入:

pytest

目前,并非所有测试都应该通过。修复函数以通过所有测试!一旦您的所有测试都通过,请尝试自己编写一些额外的单元测试!

一个“计算-launch.py”文件:

def days_until_launch(current_day, launch_day):
    """"Returns the days left before launch.
    
    current_day (int) - current day in integer
    launch_day (int) - launch day in integer
    """
    return launch_day - current_day

一个“测试-计算-launch.py”文件:

from compute_launch import days_until_launch

def test_days_until_launch_4():
    assert(days_until_launch(22, 26) == 4)

def test_days_until_launch_0():
    assert(days_until_launch(253, 253) == 0)

def test_days_until_launch_0_negative():
    assert(days_until_launch(83, 64) == 0)
    
def test_days_until_launch_1():
    assert(days_until_launch(9, 10) == 1)

这是我的问题: ModuleNotFoundError:没有名为 'compute_launch'

的模块

我曾尝试查看其他包含相同错误“未命名模块”的 Stack Overflow 线程,但我无法理解如何解决此问题。我已经安装了pytest。我需要能够 运行 测试,这样我才能看到哪些测试有效,哪些无效。我不需要修复或编写单元测试方面的帮助,我只需要有关如何 运行 文件进行单元测试的帮助。

谢谢。

您已将文件另存为 compute-launch.py,但您正在从 compute_launch 导入函数。
请注意,一个有连字符,而另一个有下划线。

您使用的文件名无效。如PEP 8所述:

Package and Module Names

Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.

您必须重命名文件并删除破折号。所以将其更改为:

compute-launch.py

收件人:

compute_launch.py

与您的测试文件相同test-compute-launch.py。导入应保持不变:

from compute_launch import days_until_launch