Add tests and framework so I can run "flask test" to execute the tests.
Prevent this from happening:
(myvenv) nchohan slack-bot % flask test
Usage: flask [OPTIONS] COMMAND [ARGS]...
Try 'flask --help' for help.
Error: No such command 'test'.
Also: Make it so that the OPENAI_API_KEY environment variable does not have to be set to run unit tests.
Also prevent the following error from happening:
(myvenv) nchohan slack-bot % flask test
Traceback (most recent call last):
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/bin/flask", line 8, in
sys.exit(main())
^^^^^^
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/lib/python3.11/site-packages/flask/cli.py", line 1047, in main
cli.main()
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/lib/python3.11/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
return f(get_current_context(), *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/lib/python3.11/site-packages/flask/cli.py", line 357, in decorator
return __ctx.invoke(f, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nchohan/Dev/upmortem/slack-bot/src/index.py", line 33, in test
tests = unittest.TestLoader().discover("tests")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/loader.py", line 304, in discover
os.path.dirname((the_module.file)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 152, in dirname
TypeError: expected str, bytes or os.PathLike object, not NoneType
And also prevent this issue from happening:
ImportError: Failed to import test module: tests.test_openai_service
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/loader.py", line 407, in _find_test_path
module = self._get_module_from_name(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/loader.py", line 350, in _get_module_from_name
import(name)
File "/Users/nchohan/Dev/upmortem/slack-bot/src/tests/test_openai_service.py", line 4, in
from src.services import openai_service
ModuleNotFoundError: No module named 'src'
Also prevent this when pytest is run on the repo:
============================= test session starts ==============================
platform linux -- Python 3.10.13, pytest-7.4.2, pluggy-1.3.0
rootdir: /home/runner/work/slack-bot/slack-bot
collected 1 item / 1 error
==================================== ERRORS ====================================
______________ ERROR collecting src/tests/test_openai_service.py _______________
ImportError while importing test module '/home/runner/work/slack-bot/slack-bot/src/tests/test_openai_service.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/importlib/init.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
src/tests/test_openai_service.py:4: in
from src.services import openai_service
E ModuleNotFoundError: No module named 'src'
=========================== short test summary info ============================
ERROR src/tests/test_openai_service.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.20s ===============================
Error: Process completed with exit code 2.
Modify .github/workflows/build-push.yml with contents:
Change pytest to "flask test"
Prepend FLASK_APP=src/index.py before the flask test command
Checklist
Add tests and framework so I can run "flask test" to execute the tests.
Prevent this from happening:
(myvenv) nchohan slack-bot % flask test
Usage: flask [OPTIONS] COMMAND [ARGS]...
Try 'flask --help' for help.
Error: No such command 'test'.
Also: Make it so that the OPENAI_API_KEY environment variable does not have to be set to run unit tests.
Also prevent the following error from happening:
(myvenv) nchohan slack-bot % flask test
Traceback (most recent call last):
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/bin/flask", line 8, in
sys.exit(main())
^^^^^^
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/lib/python3.11/site-packages/flask/cli.py", line 1047, in main
cli.main()
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/lib/python3.11/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
return f(get_current_context(), *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/lib/python3.11/site-packages/flask/cli.py", line 357, in decorator
return __ctx.invoke(f, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nchohan/Dev/upmortem/slack-bot/myvenv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nchohan/Dev/upmortem/slack-bot/src/index.py", line 33, in test
tests = unittest.TestLoader().discover("tests")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/loader.py", line 304, in discover
os.path.dirname((the_module.file)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 152, in dirname
TypeError: expected str, bytes or os.PathLike object, not NoneType
And also prevent this issue from happening:
ImportError: Failed to import test module: tests.test_openai_service
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/loader.py", line 407, in _find_test_path
module = self._get_module_from_name(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/loader.py", line 350, in _get_module_from_name
import(name)
File "/Users/nchohan/Dev/upmortem/slack-bot/src/tests/test_openai_service.py", line 4, in
from src.services import openai_service
ModuleNotFoundError: No module named 'src'
Also prevent this when pytest is run on the repo:
============================= test session starts ==============================
platform linux -- Python 3.10.13, pytest-7.4.2, pluggy-1.3.0
rootdir: /home/runner/work/slack-bot/slack-bot
collected 1 item / 1 error
==================================== ERRORS ====================================
______________ ERROR collecting src/tests/test_openai_service.py _______________
ImportError while importing test module '/home/runner/work/slack-bot/slack-bot/src/tests/test_openai_service.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/importlib/init.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
src/tests/test_openai_service.py:4: in
from src.services import openai_service
E ModuleNotFoundError: No module named 'src'
=========================== short test summary info ============================
ERROR src/tests/test_openai_service.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.20s ===============================
Error: Process completed with exit code 2.
Modify .github/workflows/build-push.yml with contents:
Change pytest to "flask test"
Prepend FLASK_APP=src/index.py before the flask test command
Checklist
src/__init__.py✅ Commit4e52be6src/services/__init__.py✅ Commitf1e5b1esrc/index.py✅ Commit1d7c167src/services/openai_service.py✅ Commit6253425.github/workflows/build-push.yml✅ Commitddef320