-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Conversation
This should have a test, and a changelog entry. |
I agree with @The-Compiler. 👍 To test it, given that this is a somewhat coupled part of the code with the rest of the machinery, I suggest to refactor the loop which identifies the packages/modules of the entrypoint: 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, ext = os.path.splitext(fn)
hook.mark_rewrite(module_name)
elif is_package:
package_name = os.path.dirname(fn)
hook.mark_rewrite(package_name) Into its own function so the above block can become: for name in iter_rewritable_modules(package_files):
hook.mark_rewrite(name) This way you can easily unit-test the logic of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test for the new iter_rewritable_modules function
_pytest/config.py
Outdated
for name in self.iter_rewritable_modules(package_files): | ||
hook.mark_rewrite(name) | ||
|
||
def iter_rewritable_modules(self, package_files): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now this just need a test 😉
@nicoddemus pointers please. I am new to pytest |
Sure thing. 👍 I meant that now you can write a proper unit-test along this lines: @pytest.mark.parametrize('names, expected', [
(['foo', 'bar.py'], ['foo.bar']),
(['foo', 'bar.pyc'], []),
(['foo', '__init__.py'], ['foo']),
(['foo', 'bar', '__init__.py'], []),
])
def test_iter_rewritable_modules(names, expected):
from os.path import join
assert list(iter_rewritable_modules(join(*names) == expected Note that |
This also needs a changelog entry: Write a file
|
_pytest/config.py
Outdated
module_name, ext = os.path.splitext(fn) | ||
hook.mark_rewrite(module_name) | ||
module_name, _ = os.path.splitext(fn) | ||
modules.append(module_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this an actual generator instead of returning a list, replacing modules.append(module_name)
by yield module_name
.
* on linux it is '/' * on windows it is '\'
@nicoddemus Please take a look. the build has been passed. |
Thanks @srinivasreddy! |
Removed os.sep as it behaves differently linux and windows