Ich wollte den Klassenpfad von Pathlib verspotten. Nehmen wir an, ich habe eine Funktion namens FunctionX (), in der das Pfadobjekt erstellt wird. Dies wirft eine Führung. Wie kann ich das zum Laufen bringen? Mein Test sieht aus wie folgt: < /p>
@patch('pathlib.Path')
def test_start(self, patch_path):
patch_path.is_file.return_value = True
patch_path.exists.return_value = True
x = functionX()
self.assertTrue(x)
< /code>
def functionX():
p=Path("/some/non/existing/path/to/a/file.hpp")
if p.exists() and p.is_file():
return True
< /code>
The output is the following:
AttributeError: type object 'Path' has no attribute '_flavour'
< /code>
Can anyone help me?
Using pathlib3x instead of pathlib resolves the issue of the exception. But now I have encountered that the functions is_file() and exists() are not executed like mentioned in the return_value.
Verspottung Pathlib.Path -Objekt für Python Unittest ⇐ Python
-
- Similar Topics
- Replies
- Views
- Last post