-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Run seed scripts in DbContainer #542
Conversation
return self | ||
|
||
def _configure(self) -> None: | ||
raise NotImplementedError | ||
|
||
def _seed(self) -> None: | ||
raise NotImplementedError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realized we of course shouldn't penalize DbContainer variants for not defining this method, should do something like if not self.seeds: return
and only otherwise raise this error
@@ -30,6 +30,24 @@ def test_docker_run_mysql_8(): | |||
assert row[0].startswith("8") | |||
|
|||
|
|||
@pytest.mark.skipif(is_arm(), reason="mysql container not available for ARM") | |||
def test_docker_run_mysql_8_seed(): | |||
seeds = ("modules/mysql/tests/", ["schema.sql", "seeds.sql"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These paths are hardcoded, assuming pytest
executes with cwd
at the top of the repo, and will fail if we cd
beforehand.
Leaving it up to maintainers to agree if that's good enough, of if a more obscure __file__
related path derivation should be explored instead: is the overhead of more complex test script worth it?
New capability of "seeding" a db container, by running a database-specific command or twelve to inject data (DB schema or sample data).
|
||
>>> import sqlalchemy | ||
>>> from testcontainers.mysql import MySqlContainer | ||
>>> seed_data = ("../../tests/", ["schema.sql", "data.sql"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tradeoff: the docstring is ugly due to weird relative path to real sql files, but if I write what I mean:
>>> seed_data = ("../../tests/", ["schema.sql", "data.sql"]) | |
>>> seed_data = ("db/scripts/", ["schema.sql", "data.sql"]) |
Well then the doctests fail, which won't work either!
see discussion in #541 |
New capability of "seeding" a db container, by running a database-specific command or twelve to inject data (DB schema or sample data).
Ref #541, implemented for MySQL but generalizeable