简体   繁体   中英

Python module not reloading after importlib.reload()

I recently changed a function in a module I've imported to take a single argument. However, python does not seem to recognize this change despite trying to reload the module.

# 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

What gives?

The only solution I found was to reinstall my package pip3 install -e.

Seems like there must be a better way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM