Python模块在导入库重新加载()

2024-09-30 00:27:05 发布

您现在位置:Python中文网/ 问答频道 /正文

最近,我在导入的模块中更改了一个函数,使其只接受一个参数。然而,尽管尝试重新加载模块,python似乎没有意识到这一变化。你知道吗

# config.py in bettered package
def read_config(config: str = None) -> ConfigParser:
    """Process and check a given configuration file.
    Raises:
        FileNotFoundError: No configuration file found.
        ValueError: Configuration value error.
    Returns:
        Complete ConfigParser object.
    """
    config = ConfigParser()

    if config:
        config_location = config
    else:
        config_location = CONFIG_LOCATIONS

    files_read = config.read(config_location)
    if not files_read:
        raise FileNotFoundError('No configuration file at the following '
                                f'location(s): {config_location}')

    _check_config(config)

    return config
"""Test module for the configuration file."""

import pytest

from bettered import config
import importlib
importlib.reload(config)


def test_config_exists():
    """Test FileNotFoundError raised when no configuration file found."""
    with pytest.raises(FileNotFoundError):
        config.read_config('')
$ pytest
   def test_config_exists():
        """Test FileNotFoundError raised when no configuration file found."""
        with pytest.raises(FileNotFoundError):
>           config.read_config('')
E           TypeError: read_config() takes 0 positional arguments but 1 was given

有什么好处?你知道吗


Tags: 模块testimportconfigreadpytestdefcheck

热门问题