Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/1313.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure ``TOX_WORK_DIR`` is a native string in ``os.environ`` - by :user:`asottile`.
2 changes: 1 addition & 1 deletion src/tox/session/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def main(args):
try:
config = load_config(args)
config.logdir.ensure(dir=1)
with set_os_env_var("TOX_WORK_DIR", config.toxworkdir):
with set_os_env_var(str("TOX_WORK_DIR"), config.toxworkdir):
session = build_session(config)
exit_code = session.runcommand()
if exit_code is None:
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/session/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ def assert_popen_env(res):
if tox_id != "GLOB":
assert env["TOX_ENV_NAME"] == tox_id
assert env["TOX_ENV_DIR"] == os.path.join(res.cwd, ".tox", tox_id)
# ensure native strings for environ for windows
for k, v in env.items():
assert type(k) is str, (k, v, type(k))
Copy link

@luzfcb luzfcb May 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asottile
A technical question: Why not use isinstance(k, str) instead of type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type(...) is a stronger assertion here than isinstance -- I'm guarding against subclasses of str

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to the explanation.

In [1]: class foostr(str):
   ...:     pass
   ...:
   ...:

In [2]: x = str("bar")

In [3]: y = foostr("bar")

In [4]: type(x)
Out[4]: str

In [5]: type(y)
Out[5]: __main__.foostr

In [6]: isinstance(x, str)
Out[6]: True

In [7]: isinstance(y, str)
Out[7]: True

In [8]: type(x) is str
Out[8]: True

In [9]: type(y) is str
Out[9]: False

assert type(v) is str, (k, v, type(v))


def test_command_prev_post_ok(cmd, initproj, mock_venv):
Expand Down