Skip to content

Commit

Permalink
Add current working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Apr 26, 2020
1 parent 1843e46 commit a73dcef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.

from logging import getLogger
from os import environ, execl
from os import environ, execl, getcwd
from os.path import abspath, dirname, pathsep
from shutil import which
from sys import argv
Expand All @@ -33,6 +33,11 @@ def run() -> None:
else:
python_path = python_path.split(pathsep)

cwd_path = getcwd()

if cwd_path not in python_path:
python_path.insert(0, cwd_path)

filedir_path = dirname(abspath(__file__))

python_path = [path for path in python_path if path != filedir_path]
Expand Down
13 changes: 8 additions & 5 deletions opentelemetry-auto-instrumentation/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
# type: ignore

from os import environ
from os import environ, getcwd
from os.path import abspath, dirname, pathsep
from unittest import TestCase
from unittest.mock import patch
Expand Down Expand Up @@ -49,14 +49,17 @@ def tearDownClass(cls):
@patch.dict("os.environ", {"PYTHONPATH": ""})
def test_empty(self):
auto_instrumentation.run()
self.assertEqual(environ["PYTHONPATH"], self.auto_instrumentation_path)
self.assertEqual(
environ["PYTHONPATH"],
pathsep.join([self.auto_instrumentation_path, getcwd()]),
)

@patch.dict("os.environ", {"PYTHONPATH": "abc"})
def test_non_empty(self):
auto_instrumentation.run()
self.assertEqual(
environ["PYTHONPATH"],
pathsep.join([self.auto_instrumentation_path, "abc"]),
pathsep.join([self.auto_instrumentation_path, getcwd(), "abc"]),
)

@patch.dict(
Expand All @@ -67,7 +70,7 @@ def test_after_path(self):
auto_instrumentation.run()
self.assertEqual(
environ["PYTHONPATH"],
pathsep.join([self.auto_instrumentation_path, "abc"]),
pathsep.join([self.auto_instrumentation_path, getcwd(), "abc"]),
)

@patch.dict(
Expand All @@ -82,7 +85,7 @@ def test_single_path(self):
auto_instrumentation.run()
self.assertEqual(
environ["PYTHONPATH"],
pathsep.join([self.auto_instrumentation_path, "abc"]),
pathsep.join([self.auto_instrumentation_path, getcwd(), "abc"]),
)


Expand Down

0 comments on commit a73dcef

Please sign in to comment.