Question: use cases (beyond which unit test lib I use)
See original GitHub issueHi,
@mrbean-bremen answered a question of mine in StackOverflow, and I got interested in this lib. I am a long time python user, but unfortunately I did not give the required attention to the importance of testing. I know basics (difference of fake, stub, mock, what is a unit of code, etc).
I am practicing testing with a new project that uses pytest, and it has a module that reads XLS reports using pandas and make consolidations on numbers. I think it has potential usage to test many/most methods there, but I am not really sure since documentation says: pyfakefs will not work with Python libraries (other than os and io)
, but I suspect pandas uses os
and io
under the hood.
I also would like to know if you recommend any good materials on unit testing with fakes/pyfakefs/pytest specifically.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)
@knightjdr , @staticdev: I just had another look at pandas, and at least for
read_csv
there is a possibility to use it with pyfakefs - just to let you know in case you are interested…Pandas internally uses its
TextFileReader
to read from CSV, and this has an argumentengine
which defines which backend is used for file system access. The default is “c”, but if you set it to “python”, it will use the standard file system access and thus can be used with pyfakefs.Patching
TextFileReader
accordingly will do the trick:With pytest, this can be done using a separate fixture:
Unfortunately, this does not help for reading excel files - for that it uses the engine from one of several external packages. I will have a look at this later… would be nice to be able to do something here, as
pandas
is used a lot nowadays, and maybe integrate it into pyfakefs.@mrbean-bremen I will make tests ASAP. Unfortunately, too busy this week. It was added to my backlog =p