jeudi 5 avril 2018

Load different resources when testing in Python

First of all let me put you in context. My main background is Java and I'm working in Python since 2 months ago. I don't know if the approach it's wrong due to my Java background and in Python has a different solution or it's just a technical ignorance problem.

In Java often you have a packaging structure like:

project
   |___src
        |___main
        |     |___java/MyClass.java
        |     |___resources/properties.file 
        |
        |___test 
              |___java/MyClassTest.java
              |___resources/properties.file 

Thus, when you execute this from tests (with Maven or IDE):

this.getClass().getResourceAsStream(resourcePath);

Either Maven or IDE loads the test path in the classpath, making test resources available rather than the ones within the main package. Conversely, when previous line is executed as main, only the resources within the main path are loaded to the classpath.

My question is: Is there any mechanism in Python to simulate this feature? Does Python have other ways to manage resources depending on the execution path?

Aucun commentaire:

Enregistrer un commentaire