Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] RFC8 - Move to pytest testing tool [Issue#428] #492

Closed
wants to merge 124 commits into from

Conversation

ricardogsilva
Copy link
Member

@ricardogsilva ricardogsilva commented Dec 14, 2016

Overview

This pull request implements the changes proposed in RFC8 - Move to pytest testing tool

The work is not finished yet. I am submitting the PR already in order to have a more public place for early review for the RFC and also to allow testing the incoming changes to travis.

A rough draft of the completed/todo list and current status:

  • Allow running all tests with an sqlite database
  • Allow running all tests with a postgresql database
  • Consolidate documentation on how to run tests
  • Consolidate development requirements
  • Add license and copyright headers to new files
  • Remove older testing tasks from paverment.py
  • Remove the older runtests test runner
  • Move test cases and expected results into suite based dirs
  • Enable measuring code coverage with the pytest-cov plugin
  • A timeout threshold for tests with pytest-timeout plugin
  • Integrate with tox in order to facilitate testing with multiple python versions and database backends
  • Add meaningful docstrings to all new functions
  • Refactor the Travis configuration to reflect the new test runner
  • All tests pass with sqlite as backend and python2.6
  • All tests pass with sqlite as backend and python2.7
  • All tests pass with sqlite as backend and python3.4
  • All tests pass with sqlite as backend and python3.5
  • Clean up the git commit history
  • Alter the RFC description page in order to provide a detailed explanation on the changes introduced by this PR

I plan to complete the missing items on the list shortly and then call for a vote on the RFC. Currently I'm facing some troubles with the harvesting suite as I'm getting some errors that seem to be external to pycsw. The other suites are all passing.

Related Issue / Discussion

RFC8 - Move to pytest testing tool
Issue #428

Additional Information

I'm contemplating other tasks that could be done and that are somehow related to this PR. I've decided to keep them out of scope for this:

  • Running tests in parallel with the pytest-xdist plugin - May require further changes and I did not feel like delaying this PR even more;
  • All tests pass with postgresql as backend - There are some tests that are currently not working with postgresql. This has nothing to do with this PR, the tests are broken in the current master as well. We can tackle this more effectively once we get an automated way to run postgresql tests;
  • Allow running tests with a mysql database - Requires further development. Since this feature is not present in the current master I guess it is not a priority;
  • Subscribing to a code coverage service like codecov - This would give some visibility to our code coverage and help improving it. This particular service is free for open source projects. This seems like something to discuss with other devs (or maybe the PSC?) after merging this PR.

Contributions and Licensing

(as per https://github.com/geopython/pycsw/blob/master/CONTRIBUTING.rst#contributions-and-licensing)

  • I'd like to contribute [feature X|bugfix Y|docs|something else] to pycsw. I confirm that my contributions to pycsw will be compatible with the pycsw license guidelines at the time of contribution.
  • I have already previously agreed to the pycsw Contributions and Licensing Guidelines

These are not needed anymore on GET requests
Removed a lot of boiler plate code, simplifying things
Reorganized the location of test data files. This keeps things a bit cleaner
These are not needed anymore on GET requests
Removed a lot of boiler plate code, simplifying things
Reorganized the location of test data files. This keeps things a bit cleaner
@tomkralidis
Copy link
Member

cc @kalxas

@ricardogsilva I've done a first pass review and have provide specific comments/questions as part of the review -- very impressive work here!

Additional comments:

  • what is the difference between tests/conftest.py and tests/functionaltests/conftest.py?
  • this PR should cleanup git commits. I don't mind (and encourage) the numerous commits that are specific to the PR/RFC, but let's make sure the other changes made upstream are not re-committed here
  • what/where is the actual test runner workflow/code? A high level explanation of the workflow would be valuable so other devs wishing to update the test code have a clearer picture

source =
pycsw
.tox/*/lib/python*/site-packages/pycsw
/usr/local/lib/python*/dist-packages/pycsw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this hardcoded path safe enough or should it be abstracted somehow?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so.

  • The second line refers to paths inside the virtualenvs generated by tox, so they are always the same, and they do not depend on the base system.
  • The third line is the standard path where python packages are installed whenever they are pip installed in a debian-like system. I'm not so sure this is the same on other distros. However, I don't think it is relevant, as this configuration's purpose is for allowing the coverage output's to be treated as the same by coverage.py, specifically for the continuous integration service. Since we are using Travis, which is based on ubuntu, the paths are the expected ones.

@@ -0,0 +1,12 @@
[run]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this file for coverage.py? Is coverage.py enabled by the tox --cov flag?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Yes, .coveragerc is the configuration for running coverage.py. More details here. In our case I am using it mostly to:
    • enable branch covering, which is useful to see whether tests cover multiple options in if.. elif.. else blocks
    • allow for collecting results inside tox virtualenvs
  2. Yes, coverage is enabled in tox too. This is configured in the tox.ini. I've chosen to enable coverage only on python3.4 for now. In the future we can report coverage on all python versions and then combine them all, but this will require additional work

@@ -6,15 +6,15 @@
- Python version:
- pycsw version:
- source/distribution
- [ ] git clone
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes in this file are already committed upstream.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I really have to clean up the commit history...

- pip install -r requirements-dev.txt
- pip install -r requirements-standalone.txt
- python setup.py -q install
- pip install tox
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we just include tox in requirements-dev.txt and pip install -r requirements-dev.txt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not possible. The way in which tox works is that it is responsible for creating separate virtualenvs for each python version (and other combinations of dependencies, like one virtualenv for python3.4 with sqlite, another virtualenv for python3.4 with postgresql, etc). As such, the tox process is the one which is going to be calling pip to install the dependencies inside each virtualenv after it has been created. This happens when we run tox on the command-line. This means that tox must be installed system-wide and a priori of installing pycsw rquirements.

In short, its tox's job to install the requirements, so tox has to be already installed and there is no benefit in including it in requirements.txt.

@@ -48,6 +48,9 @@

# -- General configuration -----------------------------------------------------

# locale
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes in this file are already committed upstream.

@@ -0,0 +1,30 @@
# This file exists to force git to include this directory in the code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this file be called .gitkeep to be consistent with other .gitkeep files in the repo?

Copy link
Member Author

@ricardogsilva ricardogsilva Jan 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd actually prefer if the other (what other .gitkeep files are there elsewhere in the codebase if not in the tests directories) files would be renamed to .gitignore and would have a textual description of their purpose, as I've done here.

It took me a while to understand what this .gitkeep thing was. It is not a git feature and is therefore not documented in the git docs. It is merely a convention that these files are called .gitkeep. IMHO using .gitignore with a brief explanation of the file's purpose inside is more explicit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, Can you make this consistency change across the codebase?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I can do it :)
Maybe after this has been merged?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, thanks!

@@ -0,0 +1,5 @@
Exception-Harvest-missing-resourcetype,service=CSW&version=2.0.2&request=Harvest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file should be git mv'd as opposed to added/deleted? This will help preserve history.

@@ -0,0 +1,30 @@
# This file exists to force git to include this directory in the code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file should be git mv'd as opposed to added/deleted? This will help preserve history.

@@ -0,0 +1,20 @@
empty,mode=oaipmh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file should be git mv'd as opposed to added/deleted? This will help preserve history.

@@ -0,0 +1,5 @@
explain,mode=sru
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file should be git mv'd as opposed to added/deleted? This will help preserve history.

@ricardogsilva
Copy link
Member Author

@tomkralidis

  1. The difference between tests/conftest.py and tests/functionaltests/conftest.py is that the first file houses general configuration for all tests while the second file has configuration specific for the tests under the functionaltests/ directory. The rationale for this is that I'd like to have a tests/unittests directory too in the near future (i.e. after this PR is merged) where some smaller unit tests will reside. These will not need the configuration used in tests/functionaltests/conftest.py.

  2. You're right I really have to clean up the commit history. I have to spend some time improving my git skills for this. I agree that stuff that has already been commited does not belong here. I'll also squash all this stuff into a smaller number of commits too.

  3. The test runner workflow for these tests is in tests/functionaltests/conftest.py. It is where the suites are discovered and set up for testing. I've tried to provide an explanation in the docstring of the pytest_generate_tests() function here. Perhaps it is not the most visible place. I'll add something to the docs/testing.rst file too in order to make it more explicit then.

@ricardogsilva
Copy link
Member Author

@tomkralidis

I'm having a difficult time figuring out how to properly clean up the git commit history and I'm kind of scared to mess thing up. Can you help me out with this? Thanks a lot in advance

@ricardogsilva
Copy link
Member Author

@tomkralidis @kalxas

It seems I've found a way to clean up the git history and commits by checking out the master and then diff'ing my changes onto it (with some more tweaking on top). It's still WIP, but I-m confident it will work. I'll report when I have it working. Afterwards I'll be closing this PR and opening another with the cleaned stuff.

@ricardogsilva
Copy link
Member Author

I am closing this PR for now. The same functionality is available in a newer PR, with a cleaner commit history

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants