Skip to content

Commit

Permalink
Convert nose setup to fixtures, fixing test failures.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Apr 1, 2024
1 parent 7427068 commit bf844a0
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions tests/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,23 @@ def test_unicode_value(self, monkeypatch):
server.destroy()


class TestPostgresDatabase:
def setup(self):
self.port = portend.find_available_local_port()
self.server = PostgresServer(HOST, self.port)
self.server.initdb()
self.server.start()
@pytest.fixture
def local_instance(request):
request.instance.port = port = portend.find_available_local_port()
server = PostgresServer(HOST, port)
try:
server.initdb()
server.start()
yield server
finally:
server.destroy()

def teardown(self):
self.server.destroy()

def test_creates_user_and_database(self):
database = PostgresDatabase('tests', user='john', host=HOST, port=self.port)
class TestPostgresDatabase:
def test_creates_user_and_database(self, local_instance):
database = PostgresDatabase(
'tests', user='john', host=HOST, port=local_instance.port
)

database.create_user()
database.create()
Expand Down

0 comments on commit bf844a0

Please sign in to comment.