So after one of the sites I had a channel for has been completely redesigned, I thought I’d “do it right” as I update the channel and actually write some tests before I start outputting any code. It took me quite some time to figure the essentials. I use PyCharm IDE for development which I thought would make it easier to run tests.
Since Plex doesn’t ship with it’s Framework source codes anymore (real shame btw), the system interpreter may be unable to work with the compiled Python files (*.pyc) based on its version, so we have to use the interpreter bundled with Plex (Settings / Project Interpreter in PyCharm)…
Edit: there was a long description of necessary steps here, but it turned out much of it was not sufficient or accurate, so instead I’m placing a link to a repo where I’m trying to create a suitable testing ‘framework’ for Plex channels:
https://bitbucket.org/czukowski/plex-test-case
Ideas and suggestions welcome. Let’s try making the channel development easier!
And here goes my question: has anybody here had any success with testing their channels and cares to share the experience?
Maybe I am not “doing it right”, but I just use Notepad++.
I put the plugin in the Plex plugin folder of PMS, and then edit and save any changes there. For me, the combo of Python, Plex API and xpath makes it easier to just put the plugin in Plex and see what the log files say. I use the Roku app for testing since it updates changes immediately. If I encounter an issue I may add some log messages for more info.
Usually the only Python errors I run into that are not easily fixed are indention issue because I did not set the file up properly to begin with in Notepad++. If I run into this, I just open the file in Python Shell and run a Check Module to find and fix the indents.
I also have a list of bookmarks and browser add-ons I use for playing with things like regex, xpath, json, and to look at the XML files Plex builds from the plugins. One of the developers wrote an add-on for Chrome to make it much easier to view and collapse/expand the Plex XML files.
@shopgirl284
By “doing it right” I meant writing the automated tests at all and not using any particular software for it. Using IDE or a notepad program is a personal preference (and I do use Notepad++ for many purposes, too) that doesn’t stand in the way of automated testing. PyCharm happened to be I guess the only software that advertized itself as a ‘full-fledged Python IDE’ and being free as well, so I gave it a try and found it okay to work with.
In my experience, refreshing Plex XMLs in the browser and searching the log files if anything went wrong prooved far too tedious. Certain changes in the code ofter required the server restart because they couldn’t be picked up by it automatically after file save, other times only some changes applied without the server restart and it produced wild issues until I realized what’s going on.
Sure, there’s no fully getting around starting up the the browser and navigate through the channel URLs, but I trust that having most of the channel’s core logic covered by tests will make life much simpler in the long run. In fact, I know for sure it’s true for the general software development 
I do know what you mean by doing it right. I was more just trying to say that I never do anything the right way (or at least the easy way).
I removed the long description of necessary steps above because much of it turned out was not sufficient or accurate, so instead I’m placing a link to a repo where I’m trying to create a suitable testing ‘framework’ for Plex channels (see above).
Ideas and suggestions welcome. Let’s try making the channel development easier! (ok, I admit, writing tests actually takes a lot of time, so it’s not exactly making it easier, but the tests will pay off in the long run when the channel has to be maintained and its code modified and refactored).
Note: as of now, this is in the early stage, the basic functions work, although may be buggy or platform dependent and there’s still much room to improvement.
My channels are small time, and I’m not sure they’re worth the pain of setting up and writing unit tests. However, I was looking through the SS-Plex code today, and I noticed that the author has a test framework built-in and unit tests written. It might be worth your while to take a look at how he’s doing it.
For me, the biggest headache is the development cycle of coding->deploying->restarting->testing->etc loop. I’m curious if others have a second dev plex media server they use on their local box, rather than restarting their production PMS, or do you just develop directly on your PMS server like shopgirl does? Or… something else? I have a dedicated Linux PMS and do my development on a Macbook. Haven’t found a seamless way to bridge the develop->test loop other than set up PMS on my Macbook.
@familyvance very interesting, thanks for the find!
As for the development cycle, I totally agree with you that it’s a big headache and it was the main reason to try and do some testing for the code I write. IDE makes it easy to run the tests on click of a button so they could be run on every change made and, in theory, deploying, restarting and testing on live PMS could be avoided altogether or at least until you’re ready to roll a feature. I’m already happy I was able to catch some sandbox errors in tests when I inadvertently write something that upsets the code restrictions and those tend to be very obscure otherwise, when observed in the logs.
As for your specific issue, if you find yourself doing deploying, restarting, etc often, you should seek a way to automate this, maybe by writing a shell script or something (SSH login, upload, unpack, PMS restart). Myself, I’m editing the files right on my PMS because it’s just a PC hooked up to a TV.