February 2021 Summaries
3 posts from Pybites
Filter
Month:
Year:
Post Summaries
Back to Blog
The article shares practical insights and tips from the author's experience with writing pytest code, focusing on common pitfalls and effective strategies for testing in Python. Key points include the importance of proper package structure, such as including an `__init__.py` file to avoid import errors, and the utility of the `pytest-pythonpath` plugin for managing PYTHONPATH. It emphasizes organizing fixtures using `conftest.py` for efficient test module management and demonstrates how to filter tests with the `-k` option or mark them for selective execution. The article also explores handling floats with `pytest.approx`, creating and cleaning up temporary files, testing exceptions with `pytest.raises`, and enhancing parameterized tests using `pytest.param`. Debugging features like `--pdb` for breakpoint debugging and the `caplog` fixture for testing logging are highlighted, along with techniques for capturing standard output using `capsys` or `capfd`. The article encourages readers to apply these tips and share additional pytest tips in the comments, promoting a culture of robust and efficient testing practices.
Feb 26, 2021
1,142 words in the original blog post.
Becoming a content provider is crucial for career advancement, but many face challenges such as tutorial paralysis and perfectionism. To overcome these hurdles, it is recommended to begin producing content and accept initial imperfections as a path to improvement. Reading extensively fuels creativity, while engaging with audiences helps identify relevant problems to solve. Accountability partners and dedicated time for deep work are vital for maintaining a consistent content production schedule. Documenting and sharing work enhances communication skills and opens opportunities. PyBites is launching a productivity course aimed at helping individuals focus and efficiently manage their content creation efforts.
Feb 25, 2021
593 words in the original blog post.
An Abstract Syntax Tree (AST) is a data structure utilized to represent the grammar of programming languages, enabling compilers to transform source code into binary code through processes such as tokenization and optimization. The Python standard library includes the `ast` module, which facilitates the creation, visitation, and modification of ASTs for Python source code. This module, although not commonly used directly, powers several popular tools that perform tasks like code testing, coverage analysis, vulnerability detection, autocompletion, and reformatting. The article demonstrates the usefulness of the AST module through an analysis of PyBites Bite exercises, revealing the popularity of certain built-in functions and modules. Additionally, the text explains how to dissect, visit, and modify ASTs using various techniques and APIs, illustrating these concepts with examples of transforming and executing code. The discussion underscores the added complexity of understanding AST nodes and attributes due to Python's evolving language features, while also offering practical advice for leveraging the `ast` module's capabilities in Python programming.
Feb 20, 2021
3,175 words in the original blog post.