You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running tests works in Windows Subsystem for Linux but not in a Docker container. Is my general test layout correct? Looks like it's not able to find initdb. In other words, is it having conflict issues with the database created in Docker-compose.yml or does it have anything to do with that?
My test file testMyProject.py:
import unittest
import psycopg2
import testing.postgresql
from sqlalchemy import create_engine
class TestPostgresqlInteraction(unittest.TestCase):
Postgresql = testing.postgresql.PostgresqlFactory(cache_initialized_db=True)
with testing.postgresql.Postgresql() as postgresql:
engine = create_engine(postgresql.url())
dbConn = psycopg2.connect(**postgresql.dsn())
cursor = dbConn.cursor()
def setUp(self):
self.postgresql = self.Postgresql()
def tearDown(self):
self.postgresql.stop()
def testMethod(self)
conn = psycopg2.connect(**self.postgresql.dsn())
cursor = conn.cursor()
# execute cursor and do tests...
def tearDownModule(self):
self.Postgresql.clear_cache()
I run docker-compose exec myproject python3 -m unittest
Traceback:
ERROR: tests.testMyProject (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.testMyProject
Traceback (most recent call last):
File "/usr/local/lib/python3.7/unittest/loader.py", line 436, in _find_test_path
module = self._get_module_from_name(name)
File "/usr/local/lib/python3.7/unittest/loader.py", line 377, in _get_module_from_name
__import__(name)
File "/code/tests/testMyproject.py", line 40, in <module>
class TestPostgresqlInteraction(unittest.TestCase):
File "/code/tests/testMyproject.py", line 46, in TestPostgresqlInteraction
Postgresql = testing.postgresql.Postgresql(copy_data_from='/database/Dockerfile')
File "/usr/local/lib/python3.7/site-packages/testing/common/database.py", line 92, in __init__
self.initialize()
File "/usr/local/lib/python3.7/site-packages/testing/postgresql.py", line 50, in initialize
self.initdb = find_program('initdb', ['bin'])
File "/usr/local/lib/python3.7/site-packages/testing/postgresql.py", line 144, in find_program
raise RuntimeError("command not found: %s" % name)
RuntimeError: command not found: initdb
The text was updated successfully, but these errors were encountered:
tkl5
changed the title
ImportError: Failed to import test module in docker.
ImportError: Failed to import test module (in docker).
Sep 23, 2019
Running tests works in Windows Subsystem for Linux but not in a Docker container. Is my general test layout correct? Looks like it's not able to find
initdb
. In other words, is it having conflict issues with the database created in Docker-compose.yml or does it have anything to do with that?My test file
testMyProject.py
:docker-compose.yml:
I run
docker-compose exec myproject python3 -m unittest
Traceback:
The text was updated successfully, but these errors were encountered: