diff --git a/src/fs.rs b/src/fs.rs index 63932bdbaa..ab6cb8eb1a 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -81,7 +81,8 @@ pub fn normalize_path_to, R: AsRef>(path: P, project_root: } /// Convert an absolute path to be relative to the current working directory. -pub fn relativize_path(path: &Path) -> String { +pub fn relativize_path(path: impl AsRef) -> String { + let path = path.as_ref(); if let Ok(path) = path.strip_prefix(&*path_dedot::CWD) { return format!("{}", path.display()); } diff --git a/src/rules/flake8_no_pep420/rules.rs b/src/rules/flake8_no_pep420/rules.rs index 7791e4a09d..52ef33806d 100644 --- a/src/rules/flake8_no_pep420/rules.rs +++ b/src/rules/flake8_no_pep420/rules.rs @@ -21,6 +21,10 @@ impl Violation for ImplicitNamespacePackage { /// INP001 pub fn implicit_namespace_package(path: &Path, package: Option<&Path>) -> Option { if package.is_none() && path.extension().map_or(true, |ext| ext != "pyi") { + #[cfg(all(test, windows))] + let path = path + .to_string_lossy() + .replace(std::path::MAIN_SEPARATOR, "/"); // The snapshot test expects / as the path separator. Some(Diagnostic::new( ImplicitNamespacePackage(fs::relativize_path(path)), Range::default(),