From dece4d25b136a493dfeeeb516487d4d756bc69e9 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Wed, 1 Jan 2020 18:27:30 -0800 Subject: Resync through project.rst after moving tests directory --- docs/narr/myproject/MANIFEST.in | 3 ++ docs/narr/myproject/myproject/tests.py | 39 ---------------------- docs/narr/myproject/pytest.ini | 7 ++-- docs/narr/myproject/tests/__init__.py | 0 docs/narr/myproject/tests/test_it.py | 39 ++++++++++++++++++++++ docs/narr/project.rst | 61 ++++++++++++++++++---------------- 6 files changed, 79 insertions(+), 70 deletions(-) delete mode 100644 docs/narr/myproject/myproject/tests.py create mode 100644 docs/narr/myproject/tests/__init__.py create mode 100644 docs/narr/myproject/tests/test_it.py (limited to 'docs') diff --git a/docs/narr/myproject/MANIFEST.in b/docs/narr/myproject/MANIFEST.in index 1c24b8c0c..f516697f5 100644 --- a/docs/narr/myproject/MANIFEST.in +++ b/docs/narr/myproject/MANIFEST.in @@ -1,2 +1,5 @@ include *.txt *.ini *.cfg *.rst recursive-include myproject *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml *.jinja2 +recursive-include tests * +recursive-exclude * __pycache__ +recursive-exclude * *.py[co] diff --git a/docs/narr/myproject/myproject/tests.py b/docs/narr/myproject/myproject/tests.py deleted file mode 100644 index 48f0095ad..000000000 --- a/docs/narr/myproject/myproject/tests.py +++ /dev/null @@ -1,39 +0,0 @@ -import unittest - -from pyramid import testing - - -class ViewTests(unittest.TestCase): - def setUp(self): - self.config = testing.setUp() - - def tearDown(self): - testing.tearDown() - - def test_my_view(self): - from .views.default import my_view - request = testing.DummyRequest() - info = my_view(request) - self.assertEqual(info['project'], 'myproject') - - def test_notfound_view(self): - from .views.notfound import notfound_view - request = testing.DummyRequest() - info = notfound_view(request) - self.assertEqual(info, {}) - - -class FunctionalTests(unittest.TestCase): - def setUp(self): - from myproject import main - app = main({}) - from webtest import TestApp - self.testapp = TestApp(app) - - def test_root(self): - res = self.testapp.get('/', status=200) - self.assertTrue(b'Pyramid' in res.body) - - def test_notfound(self): - res = self.testapp.get('/badurl', status=404) - self.assertTrue(res.status_code == 404) diff --git a/docs/narr/myproject/pytest.ini b/docs/narr/myproject/pytest.ini index 332cf0d04..5c8c59068 100644 --- a/docs/narr/myproject/pytest.ini +++ b/docs/narr/myproject/pytest.ini @@ -1,3 +1,6 @@ [pytest] -testpaths = myproject -python_files = test*.py +addopts = --strict + +testpaths = + myproject + tests diff --git a/docs/narr/myproject/tests/__init__.py b/docs/narr/myproject/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/docs/narr/myproject/tests/test_it.py b/docs/narr/myproject/tests/test_it.py new file mode 100644 index 000000000..b300da34d --- /dev/null +++ b/docs/narr/myproject/tests/test_it.py @@ -0,0 +1,39 @@ +import unittest + +from pyramid import testing + + +class ViewTests(unittest.TestCase): + def setUp(self): + self.config = testing.setUp() + + def tearDown(self): + testing.tearDown() + + def test_my_view(self): + from myproject.views.default import my_view + request = testing.DummyRequest() + info = my_view(request) + self.assertEqual(info['project'], 'myproject') + + def test_notfound_view(self): + from myproject.views.notfound import notfound_view + request = testing.DummyRequest() + info = notfound_view(request) + self.assertEqual(info, {}) + + +class FunctionalTests(unittest.TestCase): + def setUp(self): + from myproject import main + app = main({}) + from webtest import TestApp + self.testapp = TestApp(app) + + def test_root(self): + res = self.testapp.get('/', status=200) + self.assertTrue(b'Pyramid' in res.body) + + def test_notfound(self): + res = self.testapp.get('/badurl', status=404) + self.assertTrue(res.status_code == 404) diff --git a/docs/narr/project.rst b/docs/narr/project.rst index e0f0be1f3..fc5cfd056 100644 --- a/docs/narr/project.rst +++ b/docs/narr/project.rst @@ -266,7 +266,8 @@ Here's sample output from a test run on Unix: .... 4 passed in 0.45 seconds -The tests themselves are found in the ``tests.py`` module in your ``cookiecutter``-generated project. Within this project generated by the ``pyramid-cookiecutter-starter`` cookiecutter, only a few sample tests exist. +The tests themselves are found in the ``test_it.py`` module in the ``tests`` package in your ``cookiecutter``-generated project. +Within this project generated by the ``pyramid-cookiecutter-starter`` cookiecutter, only a few sample tests exist. .. note:: @@ -288,7 +289,7 @@ path to the module on which we want to run tests and coverage. .. code-block:: bash - $VENV/bin/pytest --cov=myproject myproject/tests.py -q + $VENV/bin/pytest --cov=myproject myproject tests -q .. seealso:: See ``pytest``'s documentation for :ref:`pytest:usage` or invoke ``pytest -h`` to see its full set of options. @@ -535,6 +536,8 @@ The ``myproject`` project we've generated has the following directory structure: ├── .gitignore ├── CHANGES.txt ├── MANIFEST.in + ├── README.txt + ├── development.ini ├── myproject │   ├── __init__.py │   ├── routes.py @@ -546,16 +549,37 @@ The ``myproject`` project we've generated has the following directory structure: │   │   ├── 404.jinja2 │   │   ├── layout.jinja2 │   │   └── mytemplate.jinja2 - │   ├── tests.py │   └── views │   ├── __init__.py │   ├── default.py │   └── notfound.py - ├── README.txt - ├── development.ini ├── production.ini ├── pytest.ini - └── setup.py + ├── setup.py + └── tests + ├── __init__.py + └── test_it.py + + +.. index:: + single: tests + +``test_it.py`` +~~~~~~~~~~~~~~ + +The ``test_it.py`` module in the ``tests`` package includes tests for your application. + +.. literalinclude:: myproject/tests/test_it.py + :language: python + :linenos: + +This sample ``test_it.py`` file has two unit tests and two functional tests defined within it. +These tests are executed when you run ``pytest -q``. +You may add more tests here as you build your application. +You are not required to write tests to use :app:`Pyramid`. +This file is simply provided for convenience and example. + +See :ref:`testing_chapter` for more information about writing :app:`Pyramid` unit tests. The ``myproject`` :term:`Project` @@ -591,6 +615,8 @@ describe, run, and test your application. #. ``setup.py`` is the file you'll use to test and distribute your application. It is a standard :term:`Setuptools` ``setup.py`` file. +#. ``tests`` package which contains unit and functional test code for the application. + .. index:: single: PasteDeploy single: ini file @@ -819,8 +845,6 @@ The ``myproject`` :term:`package` lives inside the ``myproject`` #. A ``templates`` directory, which contains :term:`Jinja2` (or other types of) templates. -#. A ``tests.py`` module, which contains unit and functional test code for the application. - #. A ``routes.py`` module, which contains routing code for the application. #. A ``views`` package, which contains view code for the application. @@ -1040,27 +1064,6 @@ It inherits the HTML provided by ``layout.jinja2``, replacing the content block :linenos: -.. index:: - single: tests.py - -``tests.py`` -~~~~~~~~~~~~ - -The ``tests.py`` module includes tests for your application. - -.. literalinclude:: myproject/myproject/tests.py - :language: python - :linenos: - -This sample ``tests.py`` file has two unit tests and two functional tests defined -within it. These tests are executed when you run ``pytest -q``. You may add -more tests here as you build your application. You are not required to write -tests to use :app:`Pyramid`. This file is simply provided for convenience and -example. - -See :ref:`testing_chapter` for more information about writing :app:`Pyramid` -unit tests. - .. index:: pair: modifying; package structure -- cgit v1.2.3