PlexTraktSync icon indicating copy to clipboard operation
PlexTraktSync copied to clipboard

Add testing to the project

Open glensc opened this issue 3 years ago • 11 comments

With logic being isolated in newer PR's, it should make it possible to do unit and e2e testing.

Here's some related projects, which start PMS to use for testing:

  • https://github.com/pkkid/python-plexapi
  • https://github.com/andrey-yantsen/plex-api.rs

glensc avatar Mar 22 '21 07:03 glensc

Tests would be appreciated for sure. Weeks ago,I started writing some for trakt_list_util (I'm newbie about unittests so personal use only).

simonc56 avatar Apr 05 '21 17:04 simonc56

after reading this blog:

  • https://realpython.com/python-testing/

I decided to try pytest due it's simplicity writing tests and bundled with python.

Some tests are added, just to have the development aid of testing certain part of the code:

  • https://github.com/Taxel/PlexTraktSync/tree/0.7.22/tests

There's no structure there.

Ideally should have a common library that all tests can use. The object mocking should likely use something existing.

Anyway, to run the tests:

pytest path/to/test/file.py

# or 
python3 -m pytest path/to/test/file.py

glensc avatar Apr 17 '21 13:04 glensc

The tests I wrote for trakt_list_util are using mockdata from pytrakt project. Do you think it's a good idea ?

simonc56 avatar Apr 17 '21 13:04 simonc56

not sure what the mockdata is, could not find what loads those json from quick look. but pytrakt also seem to use pytest as rest runner.

glensc avatar Apr 17 '21 16:04 glensc

It is fake data so we can test each and every function of our code without connecting to a real trakt/plex account.

simonc56 avatar Apr 17 '21 17:04 simonc56

@twolaw I mean I don't know and on quick look did not understand how the files in mockdata used, so can't even say is it something they cooked on their own, or some library supports those files.

glensc avatar Apr 18 '21 05:04 glensc

It is loaded with conftest.py as a Mock object to fake all trakt answers. Very smart. We could do the same with Plex.

simonc56 avatar Apr 18 '21 07:04 simonc56

Yes, found it, already using a similar approach:

  • https://github.com/Taxel/PlexTraktSync/pull/259

glensc avatar Apr 18 '21 07:04 glensc

Yes it's good. But PyTrakt project is Mocking the trakt.core instance which is much better because very close to reality. I wonder if a copy/paste of all their test data is allowed.

simonc56 avatar Apr 18 '21 10:04 simonc56

ref Testing Click Applications

https://click.palletsprojects.com/en/8.0.x/testing/

chrillep avatar Aug 07 '21 16:08 chrillep

@chrillep thanks, but I don't think we should test e2e here, but rather unittest algorithms.

glensc avatar Aug 07 '21 17:08 glensc