[issue23097] unittest can unnecessarily modify sys.path (and with the wrong case)

2018-10-02 Thread Charlie Dyson


Charlie Dyson  added the comment:

As an aside, should that be sys.path.insert(1, X)? As 0 has a special meaning 
(I've often thought this is a slightly odd convention).

Another aside: I noticed this because I was looking to write a module finder, 
and thought I could extract one out of this function. It would be nice to have 
a module-crawler function, and write discover() in terms of that.

--
nosy: +cdyson37

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23097] unittest can unnecessarily modify sys.path (and with the wrong case)

2018-09-22 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23097] unittest can unnecessarily modify sys.path (and with the wrong case)

2015-03-21 Thread Mark Lawrence

Changes by Mark Lawrence breamore...@yahoo.co.uk:


--
nosy: +michael.foord

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23097
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23097] unittest can unnecessarily modify sys.path (and with the wrong case)

2014-12-21 Thread Chris Jerdonek

New submission from Chris Jerdonek:

I have observed that when running unit tests using unittest's test discovery, 
unittest can simultaneously (1) modify sys.path unnecessarily (by adding a path 
that is already in sys.path with a different case), and (2) modify sys.path by 
adding a path of the wrong case.

This occurs for me on Mac OS X with the default case-insensitive file system.

If the path--

'/Users/chris/Dev/python/my_package'

is already in sys.path, running unittest's test discovery will prepend sys.path 
with the following:

'/Users/chris/dev/python/my_package'

Aside from causing unnecessary modifications of sys.path, this also causes an 
issue in coverage, for example:

https://bitbucket.org/ned/coveragepy/issue/348

The relevant code is here in unittest/loader.py (with `top_level_dir` starting 
out as os.curdir):

top_level_dir = os.path.abspath(top_level_dir)

if not top_level_dir in sys.path:
# all test modules must be importable from the top level directory
# should we *unconditionally* put the start directory in first
# in sys.path to minimise likelihood of conflicts between installed
# modules and development versions?
sys.path.insert(0, top_level_dir)
self._top_level_dir = top_level_dir

(from 
https://hg.python.org/cpython/file/75ede5bec8db/Lib/unittest/loader.py#l259 )

The issue occurs when os.path.abspath(top_level_dir) is already in sys.path but 
with a different case.  (Note that if os.path.abspath() returned a path with 
the right case, then the unittest code would be okay.)

See also these two threads regarding obtaining the correct case for a path:

1. https://mail.python.org/pipermail/python-dev/2010-September/103823.html
2. https://mail.python.org/pipermail/python-ideas/2010-September/008153.html

--
components: Library (Lib)
messages: 232993
nosy: chris.jerdonek
priority: normal
severity: normal
status: open
title: unittest can unnecessarily modify sys.path (and with the wrong case)
type: behavior
versions: Python 3.4, Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23097
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com