Some refactoring to ease unit testing
Use pytest fixtures, adapt tests to refactoring