Skip to content

Unable to run coverage tool using embedded python using the -m option or when copied to different path locations in windows #739

Open
@gourish2k

Description

@gourish2k

I am trying to run the python coverage tool using embedded python downloaded from https://www.python.org/ftp/python/3.6.1/python-3.6.1-embed-amd64.zip
The following are the steps I followed to run a test code using coverage module.

  1. After downloading python-3.6.1-embed-amd64.zip, I uncompress the files to D:\some_directory\python-3.6.1-embed-amd64

  2. cd python-3.6.1-embed-amd64

  3. python get-pip.py

  4. python -mpip install coverage

  5. python-3.6.1-embed-amd64\python36._pth is changed to

    python36.zip
    Lib\site-packages
    .
    # Uncomment to run site.main() automatically
    #import site
  1. In case if there is an internet proxy to used then use the following command

    SET HTTP_PROXY=http://username:password@proxy_ip:proxy_port

  2. python -mpip install coverage

Create test files as follows

The file module_prog.py is as follows

# -*- coding: utf-8 -*-
"""
    Dummy method for testing
"""


def method_to_tested() -> None:
    """
    Method To be tested
    """
    print("Called method to be tested")

The file test_module.py is as follows

""" Unit test script for testing File : test_module.py
"""

import unittest
from module_prog import method_to_tested


class TestMethods(unittest.TestCase):
    """ Testing the methods """

    def test_method_to_tested(self):
        method_to_tested()

if __name__ == "__main__":
    unittest.main(warnings='ignore')
  1. I run the following
    D:\some_directory\python-3.6.1-embed-amd64>python test_module.py

    Called method to be tested
    .
    ----------------------------------------------------------------------
    Ran 1 test in 0.000s

    OK
  1. But if I run the instruction as mentioned below using converage I get the following error.
    D:\some_directory\python-3.6.1-embed-amd64>python -mcoverage run test_module.py

    Traceback (most recent call last):
      File "test_module.py", line 4, in <module>
        import unittest
    ModuleNotFoundError: No module named 'unittest'

If I run the command

  Scripts\converage.exe run test_module.py

Then coverage run successfully,
But if I move the embedded python to another directory and try to run the same command as above then I get the following error

D:\some_other_directory\python-3.6.1-embed-amd64>Scripts\coverage.exe run test_module.py

Fatal error in launcher: Unable to create process using 
'"d:\some_directory\python-3.6.1-embed-amd64\python.exe" "D:\some_other_directory\python-3.6.1-embed-amd64\Scripts\coverage.exe" run test_module.py'

How can I make coverage run as a python module in case the python is embedded python

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions