Skip to content

Commit

Permalink
add dotenv (lesson #7)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemonsh committed Jul 4, 2023
1 parent 0804a98 commit bc38f65
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
File renamed without changes.
5 changes: 2 additions & 3 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[pytest]
# env_override_existing_values = 1
pythonpath = . src
env_files =
.env-test

pythonpath = . src/candies
.test.env
24 changes: 22 additions & 2 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pydantic import BaseSettings
import os


class Settings(BaseSettings):
Expand All @@ -16,7 +15,28 @@ def DB_URL(self):
return f"postgresql+psycopg2://{self.DB_USER}:{self.DB_PASS}@{self.DB_HOST}:{self.DB_PORT}/{self.DB_NAME}"

class Config:
env_file = ".env" if os.environ.get("MODE") != "TEST" else ".env-test"
env_file = ".env"


settings = Settings()


# from dotenv import dotenv_values

# config = dotenv_values(".env")

# DB_HOST=config.get("DB_HOST")
# DB_PORT=config.get("DB_PORT")
# DB_USER=config.get("DB_USER")
# DB_PASS=config.get("DB_PASS")
# DB_NAME=config.get("DB_NAME")
# DB_URL=f"postgresql+psycopg2://{DB_USER}:{DB_PASS}@{DB_HOST}:{DB_PORT}/{DB_NAME}"


# class settings:
# DB_HOST=DB_HOST
# DB_PORT=DB_PORT
# DB_USER=DB_USER
# DB_PASS=DB_PASS
# DB_NAME=DB_NAME
# DB_URL=DB_URL
4 changes: 0 additions & 4 deletions src/conftest.py

This file was deleted.

Empty file removed tests/__init__.py
Empty file.
File renamed without changes.
4 changes: 4 additions & 0 deletions tests/test_list_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
from src.db import Base, engine
from src.candies.models import Candies

from src.config import settings


@pytest.fixture(scope="session", autouse=True)
def setup_db():
print(f"{settings.DB_NAME=}")
assert settings.MODE == "TEST"
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)

Expand Down

0 comments on commit bc38f65

Please sign in to comment.