Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed#2591: Replaced os.sep with '/' as it behaves differently on linux and windows. #2630

Merged
merged 1 commit into from
Aug 6, 2017
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 AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ Samuele Pedroni
Segev Finer
Simon Gomizelj
Skylar Downes
Srinivas Reddy Thatiparthy
Stefan Farmbauer
Stefan Zimmermann
Stefano Taschini
Expand Down
25 changes: 15 additions & 10 deletions _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,18 @@ def __repr__(self):
FILE_OR_DIR = 'file_or_dir'


def _iter_rewritable_modules(package_files):
for fn in package_files:
is_simple_module = '/' not in fn and fn.endswith('.py')
is_package = fn.count('/') == 1 and fn.endswith('__init__.py')
if is_simple_module:
module_name, _ = os.path.splitext(fn)
yield module_name
elif is_package:
package_name = os.path.dirname(fn)
yield package_name


class Config(object):
""" access to configuration values, pluginmanager and plugin hooks. """

Expand Down Expand Up @@ -1041,15 +1053,8 @@ def _mark_plugins_for_rewrite(self, hook):
for entry in entrypoint.dist._get_metadata(metadata)
)

for fn in package_files:
is_simple_module = os.sep not in fn and fn.endswith('.py')
is_package = fn.count(os.sep) == 1 and fn.endswith('__init__.py')
if is_simple_module:
module_name, ext = os.path.splitext(fn)
hook.mark_rewrite(module_name)
elif is_package:
package_name = os.path.dirname(fn)
hook.mark_rewrite(package_name)
for name in _iter_rewritable_modules(package_files):
hook.mark_rewrite(name)

def _warn_about_missing_assertion(self, mode):
try:
Expand Down Expand Up @@ -1351,7 +1356,7 @@ def determine_setup(inifile, args, warnfunc=None):
rootdir, inifile, inicfg = getcfg(dirs, warnfunc=warnfunc)
if rootdir is None:
rootdir = get_common_ancestor([py.path.local(), ancestor])
is_fs_root = os.path.splitdrive(str(rootdir))[1] == os.sep
is_fs_root = os.path.splitdrive(str(rootdir))[1] == '/'
if is_fs_root:
rootdir = ancestor
return rootdir, inifile, inicfg or {}
Expand Down
1 change: 1 addition & 0 deletions changelog/2591.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correctly consider ``/`` as the file separator to automatically mark plugin files for rewrite on Windows.
12 changes: 11 additions & 1 deletion testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

import _pytest._code
from _pytest.config import getcfg, get_common_ancestor, determine_setup
from _pytest.config import getcfg, get_common_ancestor, determine_setup, _iter_rewritable_modules
from _pytest.main import EXIT_NOTESTSCOLLECTED


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

@pytest.mark.parametrize('names, expected', [
(['bar.py'], ['bar']),
(['foo', 'bar.py'], []),
(['foo', 'bar.pyc'], []),
(['foo', '__init__.py'], ['foo']),
(['foo', 'bar', '__init__.py'], []),
])
def test_iter_rewritable_modules(self, names, expected):
assert list(_iter_rewritable_modules(['/'.join(names)])) == expected


class TestConfigFromdictargs(object):
def test_basic_behavior(self):
Expand Down