Blackbriar
Blackbriar

Reputation: 507

What is the proper way to include a python class from another visual studio project?

In visual studio 2013, I made up a python solution with a source code project PythonApplication1 and a unit test project named PythonApplication.UnitTests. This is the folder structure:

enter image description here

In the unit test project, I added a search path to the PythonApplication1-Project. But when I run unit tests, the following error occurs:

...PathToSolution\PythonApplication1\PythonApplication1.UnitTests\Test_MyOwnClass.py", line 2, in from MyOwnClass import MyOwnClass ModuleNotFoundError: No module named 'MyOwnClass'

I also tried to add the path to my PythonSettings file, but got the same result out of it. Here is the content of PythonSettings.json:

{
"TestFramework": "unittest",
"UnitTestRootDirectory": "PythonApplication1.UnitTests",
"UnitTestPattern": "Test_*.py",
"SearchPaths": [ "..\PythonApplication1" ]
}

Content of MyOwnClass.py:

class MyOwnClass:
    attribute1 = 0

Content of Test_MyOwnClass.py:

import unittest
from MyOwnClass import MyOwnClass

class Test_test1(unittest.TestCase):
    def test_A(self):
        myOwn = MyOwnClass()
        self.assertEqual( 0, myOwn.attribute1 )

What Did I miss when integrating MyOwnClass to my unit test project?

Upvotes: 1

Views: 80

Answers (0)

Related Questions