I have a Python script which is responsible for updating SVN repository (in a nutshell) and checking it.

Now I'd like to write some functional tests for the script. To check whether SVN update has been performed correctly, I have an idea for manual test scenario, to check at first revision number of a particular path, perform actual SVN update and check if revision number is changed.

But I'm wondering what is the best way to test anything like that with Python.

Should I really perform the SVN update, which may take a lot of time? Or maybe this is a good place for mocks? (I've never used any mocks, but as fair as I know they are mainly dedicated for unit testing, not functional testing). If mocks are okay - could you advise me how to design such kind of a test?

  • Did you consider switching to git? Today SVN is really a legacy version control system – Basile Starynkevitch May 22 '18 at 12:04
  • 2
    @BasileStarynkevitch: did you consider that comments from fanboys of a certain tool are neither helpful nor in any way solving the OPs problem? And I guess the problem stays pretty much the same for git. – Doc Brown May 22 '18 at 12:04
  • Can you programmatically create a fresh repository for each test run? – usr May 22 '18 at 12:05
  • It is not a matter of fanboys, but SVN (or CVS) is really an old tool, which has few advantages w.r.t. distributed VCS. BTW, with some conventions git (or other VCS) can be used as efficiently as svn. So if OP struggles on scripting above svn deficiencies, he might consider upgrading the VCS too – Basile Starynkevitch May 22 '18 at 12:46

It depends on what your script exactly does, which logic it performs and in which part of the script you expect the most bugs.

For example, if the script collects some files by some specific rules and then generates one or more fairly simple command line calls utilizing the svn command line program, mocking the call to svn is probably ok - you want to test the rules, not correctness of the svn command.

However, if the functional correctness depends on a complex parameter set for the svn command generated by the Python script, you maybe better off to test the "real" thing with no mocks (but not against your real production repo). I would recommend to use a local file repo, not a full-blown SVN server, for such a test. That way, as a test preparation, you can easily copy a small, prepared repository folder into a working directory and do all checkins / checkouts against this local copy. This gives you always a defined baseline for the tests.

Note further, if the script is not large and unlikely to be changed later, you should also consider if creating an automated test is really worth the hassle, and if manual testing is not enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.