# Buggy code
def do_zip_mods():
    """Build the zipmods.zip file."""
    zf = zipfile.ZipFile("tests/zipmods.zip", "w")

    # Take one file from disk.
    zf.write("tests/covmodzip1.py", "covmodzip1.py")

    # The others will be various encodings.
    source = textwrap.dedent("""\
        # coding: {encoding}
        text = u"{text}"
        ords = {ords}
        assert [ord(c) for c in text] == ords
        print(u"All OK with {encoding}")
        """)
    # These encodings should match the list in tests/test_python.py
    details = [
        ("utf8", "ⓗⓔⓛⓛⓞ, ⓦⓞⓡⓛⓓ"),
        ("gb2312", "你好，世界"),
        ("hebrew", "שלום, עולם"),
        ("shift_jis", "こんにちは世界"),
        ("cp1252", "“hi”"),
    ]
    for encoding, text in details:
        filename = "encoded_{}.py".format(encoding)
        ords = [ord(c) for c in text]
        source_text = source.format(encoding=encoding, text=text, ords=ords)
        zf.writestr(filename, source_text.encode(encoding))

    zf.close()


# Traceback (ModuleNotFoundError)
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\core\management\commands\test.py", line 23, in run_from_argv
super().run_from_argv(argv)
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\core\management\base.py", line 320, in run_from_argv
parser = self.create_parser(argv[0], argv[1])
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\core\management\base.py", line 294, in create_parser
self.add_arguments(parser)
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\core\management\commands\test.py", line 44, in add_arguments
test_runner_class = get_runner(settings, self.test_runner)
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\test\utils.py", line 301, in get_runner
test_runner_class = test_runner_class or settings.TEST_RUNNER
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\conf\__init__.py", line 76, in __getattr__
self._setup(name)
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\conf\__init__.py", line 63, in _setup
self._wrapped = Settings(settings_module)
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\conf\__init__.py", line 142, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 936, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 936, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'newproject'

# Fixed code
def do_zip_mods():
    """Build the zipmods.zip file."""
    zf = zipfile.ZipFile("tests/zipmods.zip", "w")

    # Take one file from disk.
    zf.write("tests/covmodzip1.py", "covmodzip1.py")

    # The others will be various encodings.
    source = textwrap.dedent("""\
        # coding: {encoding}
        text = u"{text}"
        ords = {ords}
        assert [ord(c) for c in text] == ords
        print(u"All OK with {encoding}")
        """)
    # These encodings should match the list in tests/test_python.py
    details = [
        ("utf8", "ⓗⓔⓛⓛⓞ, ⓦⓞⓡⓛⓓ"),
        ("gb2312", "你好，世界"),
        ("hebrew", "שלום, עולם"),
        ("shift_jis", "こんにちは世界"),
        ("cp1252", "“hi”"),
    ]
    for encoding, text in details:
        filename = "encoded_{}.py".format(encoding)
        ords = [ord(c) for c in text]
        source_text = source.format(encoding=encoding, text=text, ords=ords)
        zf.writestr(filename, source_text.encode(encoding))

    zf.close()

    zf = zipfile.ZipFile("tests/covmain.zip", "w")
    zf.write("coverage/__main__.py", "__main__.py")
    zf.close()