MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / test_is_main_thread

Function test_is_main_thread

tests_python/test_utilities.py:28–106  ·  view source on GitHub ↗

This is now skipped due to it failing sometimes (only on Windows). I (fabioz) am not 100% sure on why this happens, but when this happens the initial thread for the tests seems to be a non main thread. i.e.: With an autouse fixture with a scope='session' with the c

()

Source from the content-addressed store, hash-verified

26
27@pytest.mark.skipif(IS_WINDOWS, reason="Brittle on Windows.")
28def test_is_main_thread():
29 """
30 This is now skipped due to it failing sometimes (only on Windows).
31
32 I (fabioz) am not 100% sure on why this happens, but when this happens the initial thread for
33 the tests seems to be a non main thread.
34
35 i.e.: With an autouse fixture with a scope='session' with the code and error message below, it's
36 possible to see that at even at the `conftest` import (where indent_at_import is assigned) the
37 current thread is already not the main thread.
38
39 As far as I know this seems to be an issue in how pytest-xdist is running the tests (i.e.:
40 I couldn't reproduce this without running with `python -m pytest -n 0 ...`).
41
42 -------- Code to check error / error output ----------
43
44 from _pydevd_bundle.pydevd_utils import is_current_thread_main_thread
45 import threading
46 indent_at_import = threading.get_ident()
47
48 @pytest.yield_fixture(autouse=True, scope='session')
49 def check_main_thread_session(request):
50 if not is_current_thread_main_thread():
51 error_msg = 'Current thread does not seem to be a main thread at the start of the session. Details:\n'
52 current_thread = threading.current_thread()
53 error_msg += 'Current thread: %s\n' % (current_thread,)
54 error_msg += 'Current thread ident: %s\n' % (current_thread.ident,)
55 error_msg += 'ident at import: %s\n' % (indent_at_import,)
56 error_msg += 'curr ident: %s\n' % (threading.get_ident(),)
57
58 if hasattr(threading, 'main_thread'):
59 error_msg += 'Main thread found: %s\n' % (threading.main_thread(),)
60 error_msg += 'Main thread id: %s\n' % (threading.main_thread().ident,)
61 else:
62 error_msg += 'Current main thread not instance of: %s (%s)\n' % (
63 threading._MainThread, current_thread.__class__.__mro__,)
64
65 > raise AssertionError(error_msg)
66 E AssertionError: Current thread does not seem to be a main thread at the start of the session. Details:
67 E Current thread: <_DummyThread(Dummy-2, started daemon 7072)>
68 E Current thread ident: 7072
69 E ident at import: 7072
70 E curr ident: 7072
71 E Main thread found: <_MainThread(MainThread, started 5924)>
72 E Main thread id: 5924
73
74 conftest.py:67: AssertionError
75 """
76 from _pydevd_bundle.pydevd_utils import is_current_thread_main_thread
77 from _pydevd_bundle.pydevd_utils import dump_threads
78
79 if not is_current_thread_main_thread():
80 error_msg = "Current thread does not seem to be a main thread. Details:\n"
81 current_thread = threading.current_thread()
82 error_msg += "Current thread: %s\n" % (current_thread,)
83
84 if hasattr(threading, "main_thread"):
85 error_msg += "Main thread found: %s\n" % (threading.main_thread(),)

Callers

nothing calls this directly

Calls 6

dump_threadsFunction · 0.90
NonMainThreadClass · 0.85
getvalueMethod · 0.80
startMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected