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

Blog test using internal python package #1758

Open
marksweb opened this issue Nov 21, 2024 · 2 comments
Open

Blog test using internal python package #1758

marksweb opened this issue Nov 21, 2024 · 2 comments

Comments

@marksweb
Copy link
Contributor

Having recently switched to using uv, my version of python 3.12 doesn't come with the test module.

As stated at the top of the docs

Note
The test package is meant for internal use by Python only. It is documented for the benefit of the core developers of Python. Any use of this package outside of Python’s standard library is discouraged as code mentioned here can change or be removed without notice between releases of Python.

The blog tests import from test;

from test.support import captured_stderr

So running tox on my machine results in;

======================================================================
ERROR: blog.tests (unittest.loader._FailedTest.blog.tests)
----------------------------------------------------------------------
ImportError: Failed to import test module: blog.tests
Traceback (most recent call last):
  File "/Users/mark/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/lib/python3.12/unittest/loader.py", line 396, in _find_test_path
    module = self._get_module_from_name(name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mark/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/lib/python3.12/unittest/loader.py", line 339, in _get_module_from_name
    __import__(name)
  File "/Users/mark/dev/djangoproject.com/blog/tests.py", line 2, in <module>
    from test.support import captured_stderr
ModuleNotFoundError: No module named 'test'

In pytest there's a fixture for stderr, but not sure on the solution here.

@bmispelon
Copy link
Member

Oh interesting. I agree that this should be fixed.

I wonder if we can replaced that by contextlib.redirect_stderr: https://docs.python.org/3/library/contextlib.html#contextlib.redirect_stderr

bmispelon added a commit to bmispelon/djangoproject.com that referenced this issue Nov 24, 2024
@bmispelon
Copy link
Member

It looks like contextlib.redirect_stderr works as a replacement: #1769

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

No branches or pull requests

2 participants