feat: Run seed scripts in DbContainer#542
Conversation
| raise NotImplementedError | ||
|
|
||
| def _seed(self) -> None: | ||
| raise NotImplementedError |
There was a problem hiding this comment.
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
|
|
||
| @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.
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.
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