Ask coding questions

← Back to all posts
Having trouble setting up Python unittests with a Discord bot
GermanScot (5)

I am having trouble setting up Python unittests with a Discord bot. Error message below.

I have two files, a with the Discord code, and a with the bot code. I do not actually want to test the Discord code, but I cannot remove the "from main import *" line from the setup.

The problem seems to be with the TOKEN secret, and the loading of the environment. It doesn't get the TOKEN correctly, I think.'TOKEN'))

I have tried a couple of things, unsuccessfully so far. I haven't found any documentation on this yet. Does anyone have a tip for me on how to get this going?

Thanks in advance.

Error message:
Traceback (most recent call last):
File "", line 2, in <module>
import _test_runnertest_suite
File "/home/runner/Level-Calc-Beta/", line 2, in <module>
from main import
File "/home/runner/Level-Calc-Beta/", line 31, in <module>'TOKEN'))
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/", line 723, in run
return future.result()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/", line 702, in runner
await self.start(
args, *kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/", line 665, in start
await self.login(
args, bot=bot)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'NoneType' object has no attribute 'strip'

exit status 1