tk0miya / testing.postgresql

Apache License 2.0
290 stars 46 forks source link

RuntimeError: command not found: initdb #38

Open Priyadhana opened 2 years ago

Priyadhana commented 2 years ago

Hi , I wanted to write test-cases involving postgres for flask applicattion. When I was trying the testing.postgresql package, it's throwing this command not found: initdb error. This is the code I'm trying,

import unittest import testing.postgresql

Generate Postgresql class which shares the generated database

Postgresql = testing.postgresql.PostgresqlFactory(cache_initialized_db=True)

def tearDownModule(self):

clear cached database at end of tests

Postgresql.clear_cache()

class MyTestCase(unittest.TestCase): def setUp(self):

Use the generated Postgresql class instead of testing.postgresql.Postgresql

    self.postgresql = Postgresql()

def tearDown(self):
    self.postgresql.stop()

When I ran pytest, I'm getting this error,

src\tests\app\test_db.py:25: in Postgresql = testing.postgresql.PostgresqlFactory(cache_initialized_db=True) ..\user\appdata\local\programs\python\python39\lib\site-packages\testing\common\database.py:52: in init self.cache = self.target_class(**settings_noautostart) ..\user\appdata\local\programs\python\python39\lib\site-packages\testing\common\database.py:92: in init self.initialize() ..\user\appdata\local\programs\python\python39\lib\site-packages\testing\postgresql.py:50: in initialize self.initdb = find_program('initdb', ['bin']) ..\user\appdata\local\programs\python\python39\lib\site-packages\testing\postgresql.py:144: in find_program raise RuntimeError("command not found: %s" % name) E RuntimeError: command not found: initdb

I have set the path for "C:\Program Files\PostgreSQL\13\bin" in my environmental.

Am I missing something? Can someone help me out here.

saveshodhan commented 2 years ago

See if #35 helps..

asmaier commented 2 years ago

You need to install the postgres DB. On Mac OS simply do

brew install postgresql

Maybe the documentation should mention this as a requirement for the installation.

anentropic commented 1 year ago

after brew install postgresql I get a new error:

RuntimeError: command not found: postgres

brew info postgresql doesn't suggest anything wrong, but the fix for me was:

$ brew link postgresql
Linking /opt/homebrew/Cellar/postgresql@14/14.5_3.reinstall...
Error: Could not symlink bin/clusterdb
Target /opt/homebrew/bin/clusterdb
is a symlink belonging to libpq. You can unlink it:
  brew unlink libpq

To force the link and overwrite all conflicting files:
  brew link --overwrite postgresql@14

To list all files that would be deleted:
  brew link --overwrite --dry-run postgresql@14

$ brew link --overwrite postgresql@14
Linking /opt/homebrew/Cellar/postgresql@14/14.5_3.reinstall... 334 symlinks created.