Skip to content
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

test_mode automatically enabled if the package "sanic-testing" is present #40

Closed
cnicodeme opened this issue May 12, 2022 · 2 comments · Fixed by #61
Closed

test_mode automatically enabled if the package "sanic-testing" is present #40

cnicodeme opened this issue May 12, 2022 · 2 comments · Fixed by #61

Comments

@cnicodeme
Copy link

Describe the bug
I was wondering why my code was returning True for testing when I wasn't testing it (it behave differently when testing, such as not really sending emails).

After looking, I found out that Sanic/app.py loop over the SANIC_PACKAGES list, which includes "sanic-testing", and if present, import them.

When importing Sanic testing, this package change the test_mode to True, which is not true until the Sanic Testing package has been instantiated. IMHO, it should only change the state to true when enabled, not when imported

Code snippet

app.py, line 1836

            for package_name in SANIC_PACKAGES:
                module_name = package_name.replace("-", "_")
                try:
                    module = import_module(module_name)
                    packages.append(f"{package_name}=={module.__version__}")
                except ImportError:
                    ...

Expected behavior
Importing "sanic-testing" shouldn't change the state of Sanic (test_mode). Only when instantiating it.

Environment (please complete the following information):

  • OS: Fedora 32 v5.11.22-100.fc32.x86_64
  • Python: 3.8.10
  • Sanic version : 21.12.1
@cnicodeme
Copy link
Author

Disabling the motd avoid loading the package, and can be used as a quick and temporary fix.

app.run(motd=False)

@ahopkins
Copy link
Member

Good catch. Moving the issue to where it should really be located.

@ahopkins ahopkins transferred this issue from sanic-org/sanic May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants