void (@NotNull final T configuration, @NotNull final PsiElement element) { // When namespace packages are supported we can run tests in for of foo.spam.Bar even if foo is plain dir // otherwise we need to set "foo" as working dir and run spam.Bar. final LocalFileSystem fileSystem = LocalFileSystem.getInstance(); final ConfigurationTarget target = configuration.getTarget(); final VirtualFile workingDirectory = fileSystem.refreshAndFindFileByPath(configuration.getWorkingDirectorySafe()); Assert.assertNotNull("Working directory hasn't been set", workingDirectory); final VirtualFile projectRoot = myFixture.getTempDirFixture().getFile("."); assert projectRoot != null; assert element instanceof PsiNamedElement : "Unknown element " + element; final String elementName = ((PsiNamedElement)element).getName(); assert elementName != null; if (element instanceof PyClass && elementName.endsWith("TestDash")) { Assert.assertThat("Bad target", configuration.getTarget().getTarget(), Matchers.endsWith("test-foo.TestDash")); Assert.assertThat("Bad directory", configuration.getWorkingDirectorySafe(), Matchers.endsWith("test-test")); } else if (element instanceof PsiDirectory && elementName.endsWith("package_test")) { Assert.assertEquals("Working directory for folder should be same as folder", TargetWithVariantExtKt.asVirtualFile(target), workingDirectory); Assert.assertThat("Bad target", configuration.getTarget().getTarget(), Matchers.endsWith("package_test")); } else if (element instanceof PyFile && elementName.endsWith("test_in_package.py")) { final VirtualFile targetFile = TargetWithVariantExtKt.asVirtualFile(target); assert targetFile != null : "Failed to create virtual file for " + target; Assert.assertEquals("Working directory for file should be same as file's parent", targetFile.getParent(), workingDirectory); Assert.assertThat("Bad target", configuration.getTarget().getTarget(), Matchers.endsWith("test_in_package.py")); } else if (element instanceof PyClass && elementName.endsWith("TestLogic")) { final PsiFile targetFile = element.getContainingFile(); Assert.assertEquals("Bad working dir for class", targetFile.getVirtualFile().getParent(), workingDirectory); Assert.assertEquals("Bad configuration for class", "test_in_package.TestLogic", target.getTarget()); } else if (element instanceof PsiDirectory && elementName.endsWith("tests_folder")) { Assert.assertEquals("Bad configuration for no package folder", workingDirectory, TargetWithVariantExtKt.asVirtualFile(target)); Assert.assertThat("Bad target", configuration.getTarget().getTarget(), Matchers.endsWith("tests_folder")); } else if (element instanceof PyFile && elementName.endsWith("test_lonely.py")) { final VirtualFile targetFile = TargetWithVariantExtKt.asVirtualFile(target); assert targetFile != null : "Failed to create virtual file for " + target; Assert.assertEquals("Bad configuration for no package file", targetFile.getParent(), workingDirectory); Assert.assertThat("Bad target", configuration.getTarget().getTarget(), Matchers.endsWith("test_lonely.py")); } else if (element instanceof PyClass && elementName.endsWith("TestLonely")) { Assert.assertEquals("Bad working directory for no package class", element.getContainingFile().getVirtualFile().getParent(), workingDirectory); Assert.assertEquals("Bad configuration for class no package", "test_lonely.TestLonely", target.getTarget()); } else if (element instanceof PyFunction && elementName.endsWith("test_test")) { Assert.assertEquals("Bad configuration target", "test_functions.test_test", target.getTarget()); } else if (element instanceof PyFunction && elementName.endsWith("foo")) { Assert.assertEquals("non-test function should lead to level-based test", PyRunTargetVariant.PATH, target.getTargetType()); } else if (element instanceof PyFile && elementName.endsWith("test_foo.py")) { Assert.assertEquals("Wrong path for file-based target", PyRunTargetVariant.PATH, target.getTargetType()); } else { throw new AssertionError("Unexpected configuration " + configuration); } }