@cli.command() deftest(): """ Runs the tests without code coverage""" tests = unittest.TestLoader().discover('project/tests', pattern='test*.py') result = unittest.TextTestRunner(verbosity=2).run(tests) if result.wasSuccessful(): return0 return1
if __name__ == '__main__': cli()
现在,您可以直接使用 app 和 db 上下文:
$ docker-compose -f docker-compose-dev.yml run users flask shell
Python 3.6.5 (default, Jun 6 2018, 23:08:29) [GCC 6.4.0] on linux App: project [development] Instance: /usr/src/app/instance
>>> app <Flask 'project'>
>>> db <SQLAlchemy engine=postgres://postgres:***@users-db:5432/users_dev>
postgres=# \c users_dev You are now connected to database "users_dev" as user "postgres". users_dev=# \dt List of relations Schema | Name | Type | Owner --------+-------+-------+---------- public | users | table | postgres (1 row)
users_dev=# select * from users; id | username | email | active | created_date ----+----------+-------+--------+-------------- (0 rows)