|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 |
|
| 8 | +from tests.conftest import patch_start_tracing_child |
| 9 | + |
8 | 10 | from sentry_sdk import ( |
9 | 11 | Client, |
10 | 12 | push_scope, |
|
17 | 19 | last_event_id, |
18 | 20 | Hub, |
19 | 21 | ) |
20 | | -from sentry_sdk._compat import reraise |
| 22 | +from sentry_sdk._compat import reraise, PY2 |
21 | 23 | from sentry_sdk.integrations import ( |
22 | 24 | _AUTO_ENABLING_INTEGRATIONS, |
23 | 25 | Integration, |
@@ -736,3 +738,59 @@ def test_multiple_setup_integrations_calls(): |
736 | 738 |
|
737 | 739 | second_call_return = setup_integrations([NoOpIntegration()], with_defaults=False) |
738 | 740 | assert second_call_return == {NoOpIntegration.identifier: NoOpIntegration()} |
| 741 | + |
| 742 | + |
| 743 | +class TracingTestClass: |
| 744 | + @staticmethod |
| 745 | + def static(arg): |
| 746 | + return arg |
| 747 | + |
| 748 | + @classmethod |
| 749 | + def class_(cls, arg): |
| 750 | + return cls, arg |
| 751 | + |
| 752 | + |
| 753 | +def test_staticmethod_tracing(sentry_init): |
| 754 | + test_staticmethod_name = "tests.test_basics.TracingTestClass.static" |
| 755 | + if not PY2: |
| 756 | + # Skip this check on Python 2 since __qualname__ is available in Python 3 only. Skipping is okay, |
| 757 | + # since the assertion would be expected to fail in Python 3 if there is any problem. |
| 758 | + assert ( |
| 759 | + ".".join( |
| 760 | + [ |
| 761 | + TracingTestClass.static.__module__, |
| 762 | + TracingTestClass.static.__qualname__, |
| 763 | + ] |
| 764 | + ) |
| 765 | + == test_staticmethod_name |
| 766 | + ), "The test static method was moved or renamed. Please update the name accordingly" |
| 767 | + |
| 768 | + sentry_init(functions_to_trace=[{"qualified_name": test_staticmethod_name}]) |
| 769 | + |
| 770 | + for instance_or_class in (TracingTestClass, TracingTestClass()): |
| 771 | + with patch_start_tracing_child() as fake_start_child: |
| 772 | + assert instance_or_class.static(1) == 1 |
| 773 | + assert fake_start_child.call_count == 1 |
| 774 | + |
| 775 | + |
| 776 | +def test_classmethod_tracing(sentry_init): |
| 777 | + test_classmethod_name = "tests.test_basics.TracingTestClass.class_" |
| 778 | + if not PY2: |
| 779 | + # Skip this check on Python 2 since __qualname__ is available in Python 3 only. Skipping is okay, |
| 780 | + # since the assertion would be expected to fail in Python 3 if there is any problem. |
| 781 | + assert ( |
| 782 | + ".".join( |
| 783 | + [ |
| 784 | + TracingTestClass.class_.__module__, |
| 785 | + TracingTestClass.class_.__qualname__, |
| 786 | + ] |
| 787 | + ) |
| 788 | + == test_classmethod_name |
| 789 | + ), "The test class method was moved or renamed. Please update the name accordingly" |
| 790 | + |
| 791 | + sentry_init(functions_to_trace=[{"qualified_name": test_classmethod_name}]) |
| 792 | + |
| 793 | + for instance_or_class in (TracingTestClass, TracingTestClass()): |
| 794 | + with patch_start_tracing_child() as fake_start_child: |
| 795 | + assert instance_or_class.class_(1) == (TracingTestClass, 1) |
| 796 | + assert fake_start_child.call_count == 1 |
0 commit comments