I try to test a package that I created and for that I need to mock subprocess.Popen. I want to do this with the patch decorator but I can't specify the right target. I keep getting errors that the attribute doesn't exists in the class.

The structure of my project is like this:

```
.
|- package
|   |- __init__.py
|   |- package.py
|- tests
|   |- test_script.py

```

```py
__init__.py

from package.package import package

```

```py
package.py

from subprocess import Popen

class package:

    def __init__(self):
        self.foo = "bar"

    def echo_cmd(self):
        p = Popen("test.bat", stdout=subprocess.PIPE)
        p.wait()
        x = p.communicate()
        return x

```

```py
test_script.py

import unittest
from unittest.mock import patch, Mock

import package

class TestADBHelper(unittest.TestCase):

    def setUp(self):
        self.test = package.package()

    @patch("package.Popen")
    def test_connect_to_device_not_connected(self, mock_popen):
        """test if a device can be connected"""
        process = mock_popen.return_value
        process.returncode = 0
        process.communicate.return_value = "foo"

```

I want to mock the output of Popen. I tried different ways of importing and defining the target of the mock but I keep getting errors like:

```
AttributeError: <module 'package' from 'C:\\Users\\***\\Documents\\mock_test\\package\\__init__.py'> does not have the attribute 'Popen'

```