Skip to content

Commit 300aa1f

Browse files
author
Emanuele Palazzetti
committed
[core] add sitecustomize.py regression test
1 parent d80dfa9 commit 300aa1f

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

tests/commands/bootstrap/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CORRECT_IMPORT = True
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from __future__ import print_function
2+
3+
from ddtrace import tracer
4+
from nose.tools import ok_
5+
6+
7+
if __name__ == '__main__':
8+
import sitecustomize
9+
ok_(sitecustomize.CORRECT_IMPORT)
10+
print('Test success')

tests/commands/test_runner.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,25 @@ def test_patch_modules_from_env(self):
147147
update_patched_modules()
148148
assert EXTRA_PATCHED_MODULES["boto"] == True
149149
assert EXTRA_PATCHED_MODULES["django"] == False
150+
151+
def test_sitecustomize_run(self):
152+
# [Regression test]: ensure users `sitecustomize.py` is properly loaded,
153+
# so that our `bootstrap/sitecustomize.py` doesn't override the one
154+
# defined in users' PYTHONPATH.
155+
#
156+
# Copy the current environment and replace the PYTHONPATH. This is
157+
# required otherwise `ddtrace-run` is not found: when `env` kwarg is
158+
# passed, the environment is entirely replaced
159+
env = os.environ.copy()
160+
sitecustomize = os.path.join(os.path.dirname(__file__), 'bootstrap')
161+
162+
# Add `boostrap` module so that `sitecustomize.py` is at the bottom
163+
# of the PYTHONPATH
164+
python_path = list(sys.path) + [sitecustomize]
165+
env['PYTHONPATH'] = ':'.join(python_path)[1:]
166+
167+
out = subprocess.check_output(
168+
['ddtrace-run', 'python', 'tests/commands/ddtrace_run_sitecustomize.py'],
169+
env=env,
170+
)
171+
assert out.startswith(b"Test success")

0 commit comments

Comments
 (0)