Commit Graph

22 Commits

Author SHA1 Message Date
Leo Hemsted
a97948574a remove unused pytest flags 2020-02-13 12:52:12 +00:00
Rebecca Law
68cea04210 Fixed error message 2018-11-09 16:40:58 +00:00
Alexey Bezhan
75940c9566 Pin all application requirements in requirements.txt
The list of top-level dependencies is moved to requirements-app.txt,
which is used by `make freeze-requirements` to generate the full
list of requirements in requirements.txt.

This is based on alphagov/digitalmarketplace-api#615, so rationale
from that PR applies here.

We had a problem with unpinned packages on new deployments leading
to failed tests (e.g. alphagov/notifications-admin#2144) which is
why we're implementing this now.

After re-evaluating pipenv again, this still seems like the least
disruptive approach:

* pyup.io has experimental support for Pipfile, but doesn't respect
  version ranges or updating hashes in the lock file
* CloudFoundry buildpack recognizes and supports Pipfiles out of the
  box, but the support is relatively new. For example until recently
  CF would install dev packages during deployment. It's also based on
  generating a requirements file from the Pipfile, which doesn't
  properly support pinning VCS dependencies (eg it doesn't set the
  #egg= version, meaning pip will not upgrade the package if it's
  already installed).
* pipenv has a strict dependency resolution algorithm, which doesn't
  appear to be well documented and can cause some unexpected failures.
  For example, pipenv doesn't seem to be able to install `awscli-cwlogs`
  package at all, believing it to have a version conflict for `botocore`
  (which it doesn't list as a direct dependency) while neither `pip` nor
  `pip-tools` highlight any issues with it.
* While trying out `pipenv install` on our list of dependencies it would
  regularly fail to install utils with a "Will try again." message.
  While the installation succeeds after a retry, this doesn't inspire
  confidence.
* The switch to Pipfile and pipenv-managed virtualenvs requires a series
  of changes to `make` targets and scripts - replacing `pip install` with
  `pipenv`, removing references to requirements files and prefixing
  commands with `pipenv run`. While it's likely to simplify the overall
  process of managing dependencies, it would require time to properly
  implement across our applications and environments (Jenkins, PaaS,
  docker containers, and dev machines).
2018-07-10 14:59:04 +01:00
Chris Hill-Scott
de11751919 Merge pull request #1661 from alphagov/pytest-env
Automatically set environment vars before tests
2018-02-15 09:34:49 +00:00
Chris Hill-Scott
faa76755c3 Allow up to 10 tests to fail before stopping
This is a sensible compromise between 1 test and ALL THE TESTS.

Uses the `maxfail` option as documented here:
https://docs.pytest.org/en/latest/usage.html#stopping-after-the-first-or-n-failures
2018-02-14 13:27:06 +00:00
Chris Hill-Scott
845aad1183 Remove environment_test.sh
These config variables are now set in `pytest.ini` instead.
2018-02-14 12:19:13 +00:00
Chris Hill-Scott
e87ed0f68a Stop pytest on first failing test
If a PR is going to fail because tests aren’t passing then you:
- should know about it as quick as possible
- shouldn’t waste precious Jenkins CPU running subsequent tests

This commit adds the `-x` flag to pytest, which stops the test run as
soon as one failing test is discovered.
2018-02-14 11:54:40 +00:00
Leo Hemsted
82acec87b6 flake8 the entire repo now that the tests are good 👌 2017-11-28 17:29:43 +00:00
Leo Hemsted
90e9a2f1b3 use flake8 instead of pycodestyle
since there are thousands and thousands of errors in the tests files
at the moment, i propose fixing those errors in separate PR for now.
2017-11-28 14:28:01 +00:00
Leo Hemsted
e18e78180e update letter tests to use correct service
previously they were using sample_service fixture under the hood, but
with full permissions added - this works fine, **unless** there's
already a service with the name "sample service" in the database. This
can happen for two reasons:

* A previous test didn't tear down correctly
* This test already invoked the sample_service fixture somehow

If this happens, we just return the existing service, without modifying
its values - values that we might change in tests, such as
research mode or letters permissions.

In the future, we'll have to be vigilant! and aware! and careful! to
not use sample_service if we're doing tests involving letters, since
they create a service with a different name now
2017-09-21 11:50:49 +01:00
Leo Hemsted
2fefe8a957 use sqlalchemy hooks rather than pyscopg2
seems to play nicer with docker?
2017-08-29 18:03:15 +01:00
Leo Hemsted
3d4dbaa632 run tests in multiple threads at once
previously we didn't do this because the tests all used the same DB
(test_notifications_api), however @minglis shared a snippet that simply
creates one test db per thread.
2017-08-29 17:46:11 +01:00
Chris Hill-Scott
c2999ed5ad Use pycodestyle instead of PEP8
PEP8 was renamed to pycodestyle; this issue explains why:
https://github.com/PyCQA/pycodestyle/issues/466

This commit changes our tests to use pycodestyle instead of pep8.

It also means:
- making a couple of whitespace changes to appease the linter
- disabling warnings for bare `Except`s (ie `Except` instead of `Except
  ValueError`) – this seems like a sensible thing to catch but I’m not
  going to make meaningful code changes in this commit
2017-02-01 09:19:32 +00:00
Leo Hemsted
00cac0f88b add junit xml reporting to pytest
also add file location to gitignore preemptively
2016-08-31 15:03:28 +01:00
Leo Hemsted
9d624ef280 prevent errors if user has no venv setup at all 2016-08-23 13:56:10 +01:00
Leo Hemsted
a3843053cd improved local test-running ability
call generate-version-file before tests, since they'll fall over if the version file isn't present
use /Users/leohemsted/.virtualenvs/api rather than looking for ./venv/ - if there's some other venv already active, then don't try and look for a current venv to activate
2016-08-23 12:17:56 +01:00
bandesz
68c1135379 Create Docker build image, build project with Docker 2016-08-22 17:25:41 +01:00
Chris Hill-Scott
4f145c245a Add code coverage 2016-06-17 17:09:50 +01:00
Rebecca Law
08ba5de61b Update config
Source the configuration from an environment file, this way it is similar to how the aws environment works
2016-02-16 16:01:50 +00:00
Martyn Inglis
7b756567af Updated tests for fetch notifications by id, not simply fetch all 2016-01-19 13:45:57 +00:00
Nicholas Staples
a327702ad0 Initial code added for models and services not functional yet. Bootstrap and migrations added for db. 2016-01-07 17:50:55 +00:00
Rebecca Law
3d59c72e17 Initial version of the notify-notifications-api 2015-11-18 17:02:25 +00:00