Skip to content

Commit 76c55b3

Browse files
authored
Merge pull request #2630 from srinivasreddy/2591
Fixed#2591: Replaced os.sep with '/' as it behaves differently on linux and windows.
2 parents d5f4496 + a0101f0 commit 76c55b3

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Samuele Pedroni
155155
Segev Finer
156156
Simon Gomizelj
157157
Skylar Downes
158+
Srinivas Reddy Thatiparthy
158159
Stefan Farmbauer
159160
Stefan Zimmermann
160161
Stefano Taschini

_pytest/config.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,18 @@ def __repr__(self):
881881
FILE_OR_DIR = 'file_or_dir'
882882

883883

884+
def _iter_rewritable_modules(package_files):
885+
for fn in package_files:
886+
is_simple_module = '/' not in fn and fn.endswith('.py')
887+
is_package = fn.count('/') == 1 and fn.endswith('__init__.py')
888+
if is_simple_module:
889+
module_name, _ = os.path.splitext(fn)
890+
yield module_name
891+
elif is_package:
892+
package_name = os.path.dirname(fn)
893+
yield package_name
894+
895+
884896
class Config(object):
885897
""" access to configuration values, pluginmanager and plugin hooks. """
886898

@@ -1041,15 +1053,8 @@ def _mark_plugins_for_rewrite(self, hook):
10411053
for entry in entrypoint.dist._get_metadata(metadata)
10421054
)
10431055

1044-
for fn in package_files:
1045-
is_simple_module = os.sep not in fn and fn.endswith('.py')
1046-
is_package = fn.count(os.sep) == 1 and fn.endswith('__init__.py')
1047-
if is_simple_module:
1048-
module_name, ext = os.path.splitext(fn)
1049-
hook.mark_rewrite(module_name)
1050-
elif is_package:
1051-
package_name = os.path.dirname(fn)
1052-
hook.mark_rewrite(package_name)
1056+
for name in _iter_rewritable_modules(package_files):
1057+
hook.mark_rewrite(name)
10531058

10541059
def _warn_about_missing_assertion(self, mode):
10551060
try:
@@ -1351,7 +1356,7 @@ def determine_setup(inifile, args, warnfunc=None):
13511356
rootdir, inifile, inicfg = getcfg(dirs, warnfunc=warnfunc)
13521357
if rootdir is None:
13531358
rootdir = get_common_ancestor([py.path.local(), ancestor])
1354-
is_fs_root = os.path.splitdrive(str(rootdir))[1] == os.sep
1359+
is_fs_root = os.path.splitdrive(str(rootdir))[1] == '/'
13551360
if is_fs_root:
13561361
rootdir = ancestor
13571362
return rootdir, inifile, inicfg or {}

changelog/2591.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Correctly consider ``/`` as the file separator to automatically mark plugin files for rewrite on Windows.

testing/test_config.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
import _pytest._code
6-
from _pytest.config import getcfg, get_common_ancestor, determine_setup
6+
from _pytest.config import getcfg, get_common_ancestor, determine_setup, _iter_rewritable_modules
77
from _pytest.main import EXIT_NOTESTSCOLLECTED
88

99

@@ -308,6 +308,16 @@ def test_confcutdir_check_isdir(self, testdir):
308308
config = testdir.parseconfig('--confcutdir', testdir.tmpdir.join('dir').ensure(dir=1))
309309
assert config.getoption('confcutdir') == str(testdir.tmpdir.join('dir'))
310310

311+
@pytest.mark.parametrize('names, expected', [
312+
(['bar.py'], ['bar']),
313+
(['foo', 'bar.py'], []),
314+
(['foo', 'bar.pyc'], []),
315+
(['foo', '__init__.py'], ['foo']),
316+
(['foo', 'bar', '__init__.py'], []),
317+
])
318+
def test_iter_rewritable_modules(self, names, expected):
319+
assert list(_iter_rewritable_modules(['/'.join(names)])) == expected
320+
311321

312322
class TestConfigFromdictargs(object):
313323
def test_basic_behavior(self):

0 commit comments

Comments
 (0)