From asottile+pytest at umich.edu Sat Jun 1 11:21:03 2019 From: asottile+pytest at umich.edu (Anthony Sottile) Date: Sat, 1 Jun 2019 11:21:03 -0700 Subject: [TIP] pytest 4.6.0 released! Message-ID: The pytest team is proud to announce the 4.6.0 release! pytest is a mature Python testing tool with more than a 2000 tests against itself, passing on many different interpreters and platforms. This release contains a number of bugs fixes and improvements, so users are encouraged to take a look at the CHANGELOG: https://docs.pytest.org/en/latest/changelog.html **As a special note**: The 4.6.X series will be the last series to support Python 2 and Python 3.4. For more details, see our Python 2.7 and 3.4 support plan: https://docs.pytest.org/en/latest/py27-py34-deprecation.html For complete documentation, please visit: https://docs.pytest.org/en/latest/ As usual, you can upgrade from pypi via: pip install -U pytest Thanks to all who contributed to this release, among them: * Akiomi Kamakura * Anthony Sottile * Bruno Oliveira * Daniel Hahler * David R?thlisberger * Evan Kepner * Jeffrey Rackauckas * MyComputer * Nikita Krokosh * Raul Tambre * Thomas Hisch * Tim Hoffmann * Tomer Keren * Victor Maryama * danielx123 * oleg-yegorov Happy testing, The Pytest Development Team From ar at zeit.io Wed Jun 26 03:40:02 2019 From: ar at zeit.io (Arup Rakshit) Date: Wed, 26 Jun 2019 16:10:02 +0530 Subject: [TIP] Pytest share fixture data across the class methods Message-ID: Hi, I am using pytest to test my flask end points. I have grouped tests related to all unauthenticated access in a class as you see below: @pytest.mark.usefixtures("client_class") class TestUnauthorizedRecipesAcces: def test_update_a_recipe(self, create_recipe_record): recipe = create_recipe_record( { "cook": "9 min", "inactive": "20 min", "level": "Easy", "prep": "5 min", "title": "Grilled Salmon I", "total": "34 min", "yields": "6 servings", } ) assert ( self.client.put( url_for("recipes.recipes_api", _method="PUT", id=recipe.id), json={"inactive": "10 min", "level": "easy"}, ).status_code == 401 ) def test_delete_a_recipe(self, create_recipe_record): recipe = create_recipe_record( { "cook": "9 min", "inactive": "20 min", "level": "Easy", "prep": "5 min", "title": "Grilled Salmon I", "total": "34 min", "yields": "6 servings", } ) assert ( self.client.delete( url_for("recipes.recipes_api", _method="DELETE", id=recipe.id) ).status_code == 401 ) def test_fetch_a_recipe(self, create_recipe_record): recipe = create_recipe_record( { "cook": "9 min", "inactive": "20 min", "level": "Easy", "prep": "5 min", "title": "Grilled Salmon I", "total": "34 min", "yields": "6 servings", } ) assert ( self.client.get( url_for("recipes.recipes_api", _method="GET", id=recipe.id) ).status_code == 401 ) def test_attach_a_category_to_a_recipe( self, create_recipe_record, create_category_record ): recipe = create_recipe_record( { "cook": "45 min", "inactive": "", "level": "", "prep": "30 min", "title": "Grilled Salmon II", "total": "1 hr 15 min", "yields": "4 servings", } ) category = create_category_record({"title": "Grilled Chicken"}) assert ( self.client.post( url_for( "recipe_categories.recipe_categories_api", _method="POST", recipe_id=recipe.id, ), json={"id": category.id}, ).status_code == 401 ) def test_remove_a_category_from_a_recipe( self, create_recipe_record, create_category_record ): recipe = create_recipe_record( { "cook": "45 min", "inactive": "", "level": "", "prep": "30 min", "title": "Grilled Salmon II", "total": "1 hr 15 min", "yields": "4 servings", } ) category = create_category_record({"title": "Grilled Chicken"}) recipe.add_category(category.id) assert ( self.client.delete( url_for( "recipe_categories.recipe_categories_api", _method="DELETE", recipe_id=recipe.id, id=category.id, ) ).status_code == 401 ) Those test data I created to build urls, other than that there are no used of category, recipe records in this group. I was wondering if pytest can help to share the data across all the methods instead of creating them everytime in each method as I did above. Can you suggest me some tricks? I am looking for something like: @pytest.mark.usefixtures("client_class") class TestUnauthorizedRecipesAcces: # .... def test_remove_a_category_from_a_recipe(self): assert ( self.client.delete( url_for( "recipe_categories.recipe_categories_api", _method="DELETE", recipe_id=self.recipe.id, id=self.category.id, ) ).status_code == 401 ) How can I achieve this. Fixtures create_recipe_record, create_category_record are created in contest.py file as a function scope ( https://gitlab.com/aruprakshit/flask_awesome_recipes/blob/master/tests/conftest.py) . The tests can be seen here https://gitlab.com/aruprakshit/flask_awesome_recipes/blob/master/tests/test_recipes.py#L253 . Please give me some directions. Thanks, Arup Rakshit ar at zeit.io From asottile+pytest at umich.edu Fri Jun 28 18:16:12 2019 From: asottile+pytest at umich.edu (Anthony Sottile) Date: Fri, 28 Jun 2019 18:16:12 -0700 Subject: [TIP] pytest 5.0.0 released! Message-ID: The pytest team is proud to announce the 5.0.0 release! pytest is a mature Python testing tool with more than a 2000 tests against itself, passing on many different interpreters and platforms. This release contains a number of bugs fixes and improvements, so users are encouraged to take a look at the CHANGELOG: https://docs.pytest.org/en/latest/changelog.html **As a special note**: The 5.X series is the first series to drop support for Python 2 and Python 3.4. For more details, see our Python 2.7 and 3.4 support plan: https://docs.pytest.org/en/latest/py27-py34-deprecation.html For complete documentation, please visit: https://docs.pytest.org/en/latest/ As usual, you can upgrade from pypi via: pip install -U pytest Thanks to all who contributed to this release, among them: * Anthony Sottile * Bruno Oliveira * Daniel Hahler * Dirk Thomas * Evan Kepner * Florian Bruhin * Hugo * Kevin J. Foley * Pulkit Goyal * Ralph Giles * Ronny Pfannschmidt * Thomas Grainger * Thomas Hisch * Tim Gates * Victor Maryama * Yuri Apollov * Zac Hatfield-Dodds * curiousjazz77 * patriksevallius Happy testing, The Pytest Development Team